88.7k views
5 votes
Write a conditional statement that will sort three numbers or strings. Display the results on the webpage.

User Carmensita
by
5.9k points

1 Answer

2 votes

Answer:

<html>

<body>

<button onclick="sort1()">sort me</button>

<script>

var a=45;

var b=-1;

var c= 44;

function sort1() // function sort1

{

if (a>b && a>c)

{

if (b>c)

{

console.log(a + ", " + b + ", " +c);

}

else

{

console.log(a + ", " + c + ", " +b);

}

}

else if (b>a && b >c)

{

if (a>c)

{

console.log(b + ", " + a + ", " +c);

}

else

{

console.log(b + ", " + c + ", " +a);

}

}

else if (c>a && c>b)

{

if (a>b)

{

console.log(c + ", " + a + ", " +b);

}

else

{

console.log(c + ", " + b + ", " +a);

}

}

}

}

Output:

45 44 -1

</script>

</body>

</html>

Step-by-step explanation:

In this we create a program in javascript so we create a three variable in the function sort1() the variable i.e a,b,c after that check the condition if (a>b && a>c) In this it check if variable "a>b "and it is also greater then c then it check check for "b>c" if "b>c" then it print the value of "a,b,c" otherwise print" a,c,b" similarly other conditional statement will check display the required output in webpage .

User A Ralkov
by
5.3k points