Comparison Operators The table below explains the comparison operators. When using operators, be sure that the arguments are of the same data type; numbers should be compared with numbers, strings with strings, and so on. Please enter the corresponding operators according to the comments at right. val1 == val2 // are equal val1 ! val2 // not equal val1 <val2 // less than val1 === val2 // are strict equal (identical)
Break The break statement "jumps out" of a loop and continues executing the code after the loop. for (i = 0; i <= 10; i++) { if (i == 5) { break ; } document.write(i + "<br />"); } Try It Yourself Once i reaches 5, it will break out of the loop. You can use the return keyword to return some value immediately from the loop inside of a function. This will also break the loop. The "break" statement: Stops the whole script Ends the execution of the loop Ignores the current iteration and passes to the next
Math Object Methods The Math object contains a number of methods that are used for calculations: For example, the following will calculate the square root of a number. var number = Math . sqrt (4); document.write(number); //Outputs 2 Try It Yourself To get a random number between 1-10, use Math .random(), which gives you a number between 0-1. Then multiply the number by 10, and then take Math .ceil() from it: Math .ceil( Math .random() * 10).
Comments
Post a Comment