Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing

Example 5.16:
Type Conversion--"Multiplying" With Text


Click this button to see what happens when you multiply the value in the sVariable1 variable--a text string--by the number 10:

Depending on which version of Netscape you are using, you may see only an error message, or you may see an error message and an Alert box. (You'll have to close the Alert dialog box, then switch to the error window and close it before you can continue.)

Now click on this number to see what happens when you multiply a string containing a number by a number:



This is the script we used. First we placed this in the HEAD: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- var sVariable1 = "Fred" var sVariable2 = "15" var nVariable3 = sVariable2 * 2 //--> </SCRIPT> Then we created these buttons: <form> <input type="button" name="VariableButton" value="sVariable1 * 10: String with Text * Numeric" onclick="alert(sVariable1 * 10)"><P> <input type="button" name="VariableButton" value="nVariable2 * 2: String with a Number * Numeric" onclick="alert(nVariable3)"> </form>
Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing