Java Reference
In-Depth Information
If it does you'll need to change IE's security settings to allow active content from your computer. To do this:
1.
Open IE and select the “Internet options” menu from the Tools menu, as shown in Figure 2-5.
figure 2-5  
2.
Click the Advanced tab and then scroll down to the Security section. Check the “Allow active
content to run in files on My Computer” option, as shown in Figure 2-6.
3.
Click the OK button on the Internet Options dialog box and close Internet Explorer. Open
Example 4 from the “Fahrenheit to Centigrade” Try It Out again, and the example will now
work.
The first line of the script block is a comment, because it starts with two forward slashes ( // ). It
contains the equation for converting Fahrenheit temperatures to centigrade and is in the example code
solely for reference:
// Equation is °C = 5/9 (°F - 32).
Your task is to represent this equation in JavaScript code. You start by declaring your variables,
degFahren and degCent :
var degFahren = prompt(“Enter the degrees in Fahrenheit”,50);
var degCent;
Instead of initializing the degFahren variable to a literal value, you get a value from the user using the
prompt() function. The prompt() function works in a similar way to an alert() function, except that
as well as displaying a message, it also contains a text box in which the user can enter a value. It is this
value that will be stored inside the degFahren variable. The value returned is a text string, but this
will be implicitly converted by JavaScript to a number when you use it as a number, as discussed in the
section “Data Type Conversion” later in this chapter.
Search WWH ::




Custom Search