JavaScript Form Letter

Form Letter Assignment: You will change the code examples below so your javascript program will ask the user for 5 variables. One of your variables will be a number. After you click on the button, your program will use these 5 variables in a form letter. In addition, you will add or subtract (or any calculation) something from your number input and use this new variable in the letter, giving you a total of 6 variables. You will print out a listing of your program as well as a copy of 2 different runs of your program, and submit the papers to me after class on April 12. You should try to do this assignment before class on April 12 to see what you need help with during class.  See me right away if you have questions. Remember to save different versions of your work and return to a running copy if things get broken. Good luck!

Form Letter with a calculated variable:

You can view the source from the above link, or the code is below.  Try running it in jsfiddle. Remember this code must be put into the HTML part of jsfiddle  NOTE:  Copy and pasting this directly into JSFIDDLE may cause a problem.  Try viewing the source from the above working link if you have a problem.

<html>
<head>
<title> Greetings </title>
</head>

<body>
<h2>Greetings</h2>
<p>
Enter your name: <input type=”text” id=”nameBox” size=12 value=””>
Enter your age: <input type=”text” id=”ageid” size=12 value=””>
</p>
<input type=”button” value=”Click for Greeting”
onclick=”name = document.getElementById(‘nameBox’).value;
age = document.getElementById(‘ageid’).value;
nextyear = parseFloat(age) + 1;

document.getElementById(‘outputDiv’).innerHTML=
‘Hello ‘ + name +
‘, welcome to my page.<br>Do you mind if I call you ‘ +
name + ‘?’+ ‘ I hear you are ‘ +
age + ‘ years old. Next year you will be ‘ + nextyear + ‘ years old.'”>
<hr>
<div id=”outputDiv”></div>
</html>

Where we are headed..   Below is a link to the tic-tac-toe Javascript code you will finish so that you will teach the computer to play and win at tic-tac-toe  (OK.. sometimes a draw..)  Run and take a look at it now, if you like:

Tic Tac Toe Example: