Previous Example-|-Next Example-|-Return to Chapter Listing

Example 5.15:
Type Conversion--"Subtracting" With Text


Click this button to see the value in the sVariable2 variable, calculated by adding a numeric value to a string value containing text:

Now click here to see what happens when you subtract a numeric value from the same string:

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.)

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