Points to note:
1. Stitching only for strings;
2. equals = =;
3. Define first, then assign value, var a=10;
If you define a decimal or integer variable, the value after the equal sign is written directly.
4. All characters are in English half-width
5.>= is greater than or equal to; <= less than equals;
The 6.JS language has three blocks in HTML, but for insurance purposes, it is usually placed after
<script type= "Text-javascript" > Code on the inside </script>
<script src= "" > External style
7. Sentence order, end to add;
8./representative Except,% represents remainder
9.//Comment Line;/* Comment Multiline * /
10. Ternary operator: var L = a = b? " Equal ":" Not equal to "
alert (l); Conditions? "Content returned correctly": "Error returned content "
Examples:
- Enter three integers, x, Y, z, and eventually output in small to large mode.
varx = prompt (' input x ', "X"); vary = prompt (' Input y ', "y"); varz = prompt (' input z ', "z"); X=parseint (x); Y=parseint (y); z=parseint (z); if(x>y&&y>z) {alert (Z+ "," +y+ "," +x); } Else if(x>z&&z>y) {alert (Y+ "," +z+ "," +x); } Else if(y>x&&x>z) {alert (Z+ "," +x+ "," +y); } Else if(y>z&&z>x) {alert (x+ "," +z+ "," +y); } Else if(z>x&&x>y) {alert (Y+ "," +x+ "," +z); } Else{alert (x+ "," +y+ "," +z); }
Summary: Define three dialog boxes that can be entered prompt (), which is the default string for input, so the input is cast to integer parseint (). Then there are six more cases, where && is with: and meaning, with the alert () output, the output with the string "," and + for stitching.
2. Enter the student's name and enter the test results
If 100, "Congratulations on your * * *, full score through!" 】
If it is greater than or equal to 80 less than 100, "* *, you are excellent, keep it up! 】
If greater than or equal to 60 less than 80, "* * Good results"
Greater than or equal to 50 is less than 60, "* * just a little bit, next time must pass at least!" 】
Less than 50, "* * Are you stupid? 】
var x = prompt ("input name"); var y = prompt ("input score"); parseint (y); if (y==100) {alert ("Congratulations" +x+ ", through"); } else if (y>=80&&y<100) {alert (x+ ", very good"); } else if (y>=60&&y<80) { alert (x+ ", good"); } else if (y>=50&&y<60) { alert (x+ ", just a little bit, next time must Pass"); } else if (y<50) { alert (x+), are you an idiot? "); }
3. Standard Weight:
Men's weight = height -100±3
Lady weight = height -110±3
Enter gender, height, weight, and see if the weight is standard.
var a = prompt ("gender"); var B = prompt ("Height unit: cm"); var c = prompt ("Weight unit: KG"); parseint (b);p arseint (c); if (a== "male") { if (c>=b-100-3&&c<=b-100+3) { alert ("Weight Standard"); } else { alert ("Weight not Standard");} } else if (a== "female") {if (c>=b-110-3&&c<=b-110+3) {alert ("weight Standard");} else{alert ("Weight not Standard");} }
4. Blind Date process: Do you have a house? Do you have any money? Do you have the power?
"Get married," "Buy a house before you get married," "Make money before you buy a house and then get married."
Using if nesting as a blind date process
var a = prompt ("Is there a house?") Yes or no "), if (a!==null) {if (a==") {alert ("Marriage bar")}else{var a = prompt ("Rich?") Answer yes or no ") {if (a!==null) {if (a==") {alert ("Buy house first, then marry")} else{var a = prompt ("capable?"). Answer yes or no ") {if (a!==null) {if (a==" has ") {alert (" Make money first, buy house after, then marry ");} else {alert ("Goodbye");}}}}}
Summary: Using the If nesting, like this problem, the definition of a value can change, a!==null non-null meaning, do not enter the defined value, cannot perform the next step.
5. Equation ax2+bx+c=0; one-yuan two-time equation. Seeking root
=B2-4AC; If the <0 equation is not real roots
If >0, the equation has two different real roots X1 x2
If =0, the equation has two identical real roots
A number to open square--math.sqrt ()
var a = prompt ("input a"), var B = prompt ("input B"), var c = prompt ("input C"), A = parseint (a); b = parseint (b); c = parseint (c); var d =b*b-4*a*c;if (d>0) {var x1 = -1*b+math.sprt (d)/(2*a), var x2 = -1*b-math.sprt (d)/(2*a); alert (x1+ "," +x2 ");} else if (d==0) {var x = -1*b/(2*a); alert (x);} else if (d<0) {alert ("No real Roots");}
The use of the IF statement in JS language