January 2011
Intermediate to advanced
224 pages
5h 43m
English
One-line programs are not very interesting. When you put more than one statement into a program, the statements are executed, predictably enough, one at a time, from top to bottom. This program has two statements; the first one asks the user for a number, and the second one shows the square of that number:
var theNumber = Number(prompt("Pick a number", ""));
alert("Your number is the square root of " + (theNumber * theNumber));The function Number converts a value to a number, which is needed in
this case because the result of prompt is a string value. There are
similar functions called String and Boolean that
convert values to those types.
Sometimes, you do not want all the statements in your program to always ...
Read now
Unlock full access