Java Reference
In-Depth Information
A
Answers to Exercises
This appendix provides the answers to the questions you find at the end of each chapter in this
book.
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>
<html lang="en">
<head>
<title>Chapter 2: Question 1</title>
</head>
<body>
<script>
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 _ question1.html .
 
Search WWH ::




Custom Search