JS基础_if练习三
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8" />
5 <title>if练习3</title>
6 <script type="text/javascript">
7 /*
8 * 编写程序,由键盘输入三个整数分别存入变量num1、num2、num3,
9 * 对他们进行排序,并且从小到大输出。
10 */
11
12 //-------------------------------------------------------------------------
13
14 //获取用户输入的三个数
15 /*
16 * prompt()函数的返回值是String类型的
17 */
18 var num1 = +prompt("请输入第一个数:");
19 var num2 = +prompt("请输入第二个数:");
20 var num3 = +prompt("请输入第三个数:");
21
22
23 //找到三个数中最小的数
24 if(num1 < num2 && num1 < num3){
25 //num1最小,比较num2和num3
26 if(num2 < num3){
27 //num1 num2 num3
28 alert(num1 +","+num2 + ","+num3);
29 }else{
30 //num1 num3 num2
31 alert(num1 +","+num3 + ","+num2);
32 }
33
34 }else if(num2 < num1 && num2 < num3){
35 //num2最小,比较num1和num3
36 if(num1 < num3){
37 //num2 num1 num3
38 alert(num2 +","+num1 + ","+num3);
39 }else{
40 //num2 num3 num1
41 alert(num2 +","+num3 + ","+num1);
42 }
43
44 }else{
45 //num3最小,比较num1和num2
46 if(num1 < num2){
47 // num3 num1 num2
48 alert(num3 +","+num1 + ","+num2);
49 }else{
50 //num3 num2 num1
51 alert(num3 +","+num2 + ","+num1);
52 }
53
54 }
55
56
57 </script>
58 </head>
59 <body>
60
61 </body>
62 </html>