Display 3 numbers in ascending order

Asked

Viewed 3,674 times

1

I need the user to enter with 3 values and I show the user the three values ordered increasingly.

<html>
<head>
<title> </title> 

<script type="text/javascript">

var idade1, idade2, idade3;

idade1 = prompt ("Informe a primeira idade: ")
idade1 = eval (idade1)

idade2 = prompt ("Informe a segunda idade: ")
idade2 = eval (idade2)

idade3 = prompt ("Informe a terceira idade: ")
idade3 = eval (idade3)




</script> 
</html> 
  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

1 answer

1

The best way to do that would be with a array and use the sort():

var idade = [];
for (var i = 0; i < 3; i++) idade[i] = prompt("Informe a primeira idade: ");
idade.sort();
for (var i = 0; i < 3; i++) console.log(idade[i]);

I put in the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.