October 2009
Beginner
788 pages
18h 51m
English
This Appendix the answers to the questions you find at the end of each chapter in this book.
Write a JavaScript program to convert degrees centigrade into degrees Fahrenheit, and to write the result to the page in a descriptive sentence. The JavaScript equation for Fahrenheit to centigrade is as follows:
degFahren = 9 / 5 * degCent + 32
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<script type="text/javascript">
var degCent = prompt("Enter the degrees in centigrade",0);
var degFahren = 9 / 5 * degCent + 32;
document.write(degCent + " degrees centigrade is " + degFahren +
" degrees Fahrenheit");
</script>
</body>
</html>Save this as ch2_q1.htm.
The following code uses the prompt() function to get two numbers from the user. It then adds those two numbers together and writes the result to the page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <script language="JavaScript" type="text/javascript"> var firstNumber = prompt("Enter the first number",""); var secondNumber = prompt("Enter the second number",""); var theTotal = firstNumber + secondNumber; document.write(firstNumber + " added to " + secondNumber + " equals " + theTotal); </script> </body> ...Read now
Unlock full access