Sunday 6 December 2009

3.9 Client-side programming

I found the task of creating a JavaScript program to be quite challenging. I practiced by editing the sample JavaScript in the "Hello Page." I added two additional questions and four prompts and used the document.write function to display the questions and the user input on the webpage. I created a form by adding a final paragraph containing the word "Submit" and using the attribute "onclick." When the user clicks on "Submit," an alert pops up thanking them for their time. Click here to view the document.

The first thing I did when creating my JavaScript application was to write the code to gather input from the user. I created three prompts to determine whether the user was interested in news or sports, and to find out what type of news or sports the user wanted information about. I then used the parseInt() function to tell the application to read user input as an integer and not as text. Throughout this process, I used the w3schools' tryit editor to test the JavaScript I was writing.

The next step was to write the code to process user input. I used a series of "if statements" to tell the program what to do with the possible inputs. I then wrote the code to tell the application what output to give based on each possible input. I used the document.write function to display a link to the section of the BBC website of interest to the user. Finally, I used a "while loop" to tell the program to display an error alert with further instructions if the user input was anything other than the predefined options. This exercise, while difficult, has taught me the basics of client-side programming. Click here to view my completed program.

No comments:

Post a Comment