Use prompt return with ternary operator

1

How can I use his direct return on expressions? Because I can only use it if it will open the prompt 2 times.

I want the value, if in the condition, to be what I want, it (value) falls into the direct expression, without having to open the prompt again, understand?

let promptValue = prompt('Valor') > 10 ? 'Valor do prompt aqui' : 'Não';
console.log(promptValue);

As you can see, instead of the "Value of the prompt here" I would only get this value if I for another prompt, but in case I want the value I put in the prompt of the condition. Are you like this?

    
asked by anonymous 09.07.2018 / 14:54

1 answer

3

The prompt always returns a String , not a number. You must use Number() to convert to a number. More than that you need to save the value in a variable to be able to use as condition and option in that ternary.

const val = Number(prompt('Valor'));
let promptValue = val > 10 ? val : 'Não';
console.log(promptValue);
    
09.07.2018 / 15:00