JavaScript: Difference between revisions

From Han Wiki
Jump to navigation Jump to search
iwu
 
No edit summary
Line 1: Line 1:
=== examples ===
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
Math.max(2,4); // 4
Math.max(2,4); // 4
Line 4: Line 6:
confirm("Shall we, then?"); // OK, Cancel
confirm("Shall we, then?"); // OK, Cancel
prompt("Tell me everything you know.","..."); // default "..." OK, Cancel
prompt("Tell me everything you know.","..."); // default "..." OK, Cancel
print("X");
print("X"); // print to printer
//
var theNumber = Number(prompt("Pick a number", ""));
if (!isNaN(theNumber))
  alert("Your number is the square root of " + (theNumber * theNumber));
</syntaxhighlight>
</syntaxhighlight>

Revision as of 21:57, 2 April 2016

examples

Math.max(2,4); // 4
Math.min(2,4) + 100; // 102
confirm("Shall we, then?"); // OK, Cancel
prompt("Tell me everything you know.","..."); // default "..." OK, Cancel
print("X"); // print to printer
// 
var theNumber = Number(prompt("Pick a number", ""));
if (!isNaN(theNumber))
   alert("Your number is the square root of " + (theNumber * theNumber));