Java Reference
In-Depth Information
"</td></tr>");
 
document.write("<tr><td>round()</td><td>" + Math.round(myNumber) +
"</td></tr>");
 
document.write("</table>");
</script>
</body>
</html>
Save this as ch5_example4.html and load it into a web browser. In the prompt box, enter a number
(for example, 12.354 ), and click OK. The results of this number being passed to parseInt() , ceil() ,
floor() , and round() will be displayed in the page formatted inside a table, as shown in Figure 5-4.
figure 5-4
The first task is to get the number to be rounded from the user:
var myNumber = prompt("Enter the number to be rounded","");
Then you write out the number and some descriptive text:
document.write("<h3>The number you entered was " + myNumber + "</h3>");
document.write("<p>The rounding results for this number are</p>");
Notice how this time some HTML tags for formatting have been included—the main header being in
<h3> tags, and the description of what the table means being inside a paragraph <p> tag.
Search WWH ::




Custom Search