![]() |
|
Javascript Tutorial #3In this tutorial, I'll show how the computer can appear to be a bit more intelligent, able to make decisions based on input and modify it's output. This is achieved using the IF statement. I won't be repeating the entire text file as in previous tutorials so you will need to read them first. Here then is a simple IF script:- var myInput;
var myInput; Now a message will be displayed no matter what is input. Note that an error condition will still occur even if the word Nick or NIck (or any other upper/lower case mixture) is input. To get around this, use the command toLowerCase. Replace the following line:- if (myInput=='nick') if (myInput.toLowerCase()=='nick') So now it is possible to show you another Dialog box function which will prove useful in the future. It looks like this. var myInput; When run, the message box will display the return value of the confirm function which in this case will either be true (if OK pressed) or false (if cancel selected). This can be used as follows. var myInput; So now, it will be possible to ask the user whether or not to carry out some operation (like overwriting an existing file for example) without resorting to text input but instead using only a single mouse click. Have a play with these programs and see if you can add your own variations. The next tutorial will be a little more taxing than this one as we'll be investigating loops. Please eMail me at: nickjc@nickjc.co.uk |
|