Java Reference
In-Depth Information
A
Answers to Exercises
This Appendix provides the answers to the questions you fi nd at the end of each chapter in this topic.
Chapter 2
Exercise 1 Question
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
Exercise 1 Solution
<!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.
Search WWH ::




Custom Search