This exercise will give you some practice using arithmetic expressions. To start, this application should display a prompt dialog box like the one below that gets the temperature in Fahrenheit degrees: see image.
Then, it should display an alert dialog box like the one below that displays the temperature in Celsius:see image.
To convert a Fahrenheit temperature to Celsius, you subtract 32 from the Fahrenheit degrees and multiply that result by 5/9.
1. Here's some starting JavaScript code for this application, including a while loop and a prompt statement for getting the users entry while the entry amount isnt 999. Copy the HTML below into a file called convert_degrees.html.
< !DOCTYPE html>
< html>
< head>
< meta charset="utf-8">
< title>Convert F degrees to C degrees< /title>
< script src="http://html5shiv.googlecode.com/svn/trunk/html5.js">< /script>
< script>
var entry;
do {
entry = prompt("Enter degrees in Fahrenheitn" +
"Or enter 999 to end entries", 999);
entry = parseInt(entry);
}
while (entry != 999);
< /script>
< /head>
< body>
< section>
< h1>This page is displayed after the JavaScript is executed< /h1>
< /section>
< /body>
< /html>
2. Write the JavaScript code for deriving Celsius from Fahrenheit and displaying it in an alert dialog box as shown above. An alert box is similar to the prompt box and uses the syntax
alert("String") ;
alert(variablename);
alert(variablename + "String");
alert("String" + variablename);
alert(variablename1 + variablename2 + variablename3);
alert("String" + variablename2 + variablename3);
and so on....
3. Add data validation to the application to make sure the entry is a valid number. If the entry is invalid, the application should just display the starting prompt dialog box again. It doesnt need to display a special error message.