JavaScript And Dreamweaver Examples16 JS Zipcode Program: HW3 *** ASSIGNEMNT for HW3*** • Add a second if-else statement to check if the length of the number entered is 5 digits.
science.smith.edu/~jcardell/courses/csc103/l9.pdf
DOWNLOAD
| Find Similar
advertisement
Text Previews (text result may be not accurate) JavaScript and
DreamweaverExamples
October 15, 2007
•The World is Flat discussion
•JavaScript Examples
–Using Dreamweaver
–HTML in Dreamweaver
–JavaScript
–Homework 3 (due Friday)
JavaScript in Dreamweaver
•Dreamweaver
–Keyservedapplication
•HTML
–Used to create web pages
–Syntax uses “.7 ; ”(tags)
–JavaScript works
•JavaScript
–The high-level language we will use
Right-click on webpage a
nd “View Page Source”
Paste HTML code into Dreamweaver
Steps to Follow for Examples
•Open Example from the course page
http://www.science.smith.edu/~jcardell/Courses/CSC103/
•Enter requested information
•Right-click and select “view page source”
•Copy and paste the HTML into
Dreamweaver
•Save this file to your
H: drive with .htmor
.html extension
Hierarchy of Languages
High level languages:
FORTRAN
, C, Python, JS
Assembly language
Hardware, circuits
•SimCir
to Pippin
to Dreamweaverand
JavaScript
How Computers Work: Semester Overview
(Two paths for class discussions)
What computers
are and what they
Complexity
How computers
are evolving
How
computers
Software:
Assembly language
Hardware:
Digital circuits
Software: JavaScript
and Dreamweaver
Projects /
Reports
Discussions on
Artificial Intelligence,
and the Web
Homework Example: ZipcodeChecker
Homework Example: ZipcodeChecker
Homework Example: ZipcodeChecker
Homework Example: ZipcodeChecker
Homework Example: ZipcodeChecker
Programming: Pippin to JavaScript
•Categories of instructions (quiz 3)
–Data flow
–Arithmetic and logic
–Program control
•In Pippin, each instruction is in a single
•In JavaScript, one line of code main
contain all three types of instructions
Programming: Pippin to JavaScript
•Pippin in class example
if (W == 0)
Note the ‘==’
Z = 1
else
Z = 2
•JavaScript zipcodechecker homework
if (Zip.valueis not a number)
Note .value
write (“That is not a number!”)
else
write (“You entered a number.”)
Programming: Pippin to JavaScript
•JavaScript zipcodechecker homework
if (Zip.valueis not a number)
write (“That is not a number!”)
else
write (“You entered a number.”)
•Actual JavaScript code
Ans.value+= "\nThatis not a number!\n";
else
Ans.value+= "\nYouentered a number.\n";
Programming: Pippin to JavaScript
•Actual JavaScript code
Ans.value+= "\nThatis not a number!\n";
else
Ans.value+= "\nYouentered a number.\n";
Using HTML and Forms
•We will use HTML forms for
–Input
•text box, buttons
•radio buttons, drop-down menus …
–Action
•onClick
•onMouseOver…
–Output
•textarea
•alert box …
JS ZipcodeProgram: bodyod6;.6y-;.70;
bodyod-;.7;y20.;怀
form name="ZipF.7f;.8;orm ;name;=15.;"Z2;.2i;pF17;.7or;m"00;orm"
Enter your zipcode:
type ="text"
name ="ZipAns "
type ="button"
name ="B1"
value ="Check Zipcode"
onClick=" JavaScript:CheckZip()" ;
p000;p Resultsr00;: br
textarea
name = "Response"
/textarea/tex;.6;t-0.;re;.6a;-1.8;
If-Else Example
•Simpler than homework
–No details in hea.7;h-1.;躡.5d;d /head/7.2;he10;.5ad;.70; section
•Input
–Prompt
•Action
–User typing in a response
•Output
–Alert
http://www.science.smith.edu/~jcardell/Courses/CSC103/
If-Else Example:
If-Else Example: “If”–Correct Answer
If-Else Example: “Else”–Incorrect Answer
If-Else Example
titl;titleIf -/tit;le00;Else Control Structure/title
script language="JavaScript“type="text/javascriscri;pt13;.4 l;
ng1;.4u;
g13;.4e=;"Jav;ਓ.;Scr;ip13;.4t“;ÿ.1t1;.4y;pe=";.4;t13.;Nxt;/jav;.4;
scr;i13.;pt";pt"
varresponse = parseInt(prompt("Whatis 100 + 50?", ""))
{ alert("Thatis correct! 100 + 50 = 150") }
Homework: JS ZipcodeProgram
htmlh27.;t-1;.9m;1.6;l17.;倀
title-17.;tit;l-30;.4e1;.20;CSC
103 HW4: ZipcodeChecker/title/20.;t-1;.3i; .1;t-10;.3l2;.1e;4.3;
function CheckZip() {
varZip = document.ZipForm.ZipAns;
varAns= document.ZipForm.Response;
// Keep track of the number of tries
Count++;
Ans.value= Count + ". You entered " + Zip.value;
// Confirm that the input is a number
if (isNaN(parseInt(Zip.value)))
Ans.value+= "\nThatis not a number!\n";
else
Ans.value+= "\nYouentered a number.\n";
/script/17.; s7.;簲.1r1;.3i;-12.;p27;.5t1;.90; /head/-12;.5he;2.1;괧.500;
bodyod-;y1; .10;
form name="ZipFor-27.;演.7or;-46.;m-2;.3 ;na-5;.7m;-26.;Ϥ.;=-2;.6";-1.2;Z-41;.5i-;.1;p-30;.9F-;5.5;or-4;.1m;"000;m"
Enter your zipcode:
input
type ="text"
name ="ZipAns"
input
type ="button"
name ="B1"
value ="Check Zipcode"
onClick=" JavaScript:CheckZip()";
pp27.;က
Results: b-40.;謖.7r0;r
textarea
name = "Response"
rows = 4
cols = 50
/textarea-17.;/te;-16.;x9.;t0a;-16.;r-5;.6e1;.2a;-16.;
/form/18.;漓o28.;r-1;.4m;2.7; /body/-11;.8b2;.2o;
y28;.200;
/html/19.;ht-;.2;m33.;l19;.200;
JS ZipcodeProgram: bodyod6;.6y-;.70;
bodyod-;.7;y20.;怀
form name="ZipF.7f;.8;orm ;name;=15.;"Z2;.2i;pF17;.7or;m"00;orm"
Enter your zipcode:
type ="text"
name ="ZipAns "
type ="button"
name ="B1"
value ="Check Zipcode"
onClick=" JavaScript:CheckZip()" ;
p000;p Resultsr00;: br
textarea
name = "Response"
/textarea/tex;.6;t-0.;re;.6a;-1.8;
JS ZipcodeProgram: headhead;.90;
head-6.8;h-7.;㺭-7.3;
-5.7;titl;titleCSC 103 HW4: ZipcodeChecker-5.7;/tit;le00;/title
script language ="JavaScript-6.4;s-3.;lri;p-6.; t l;ਓn;-6.9;g5.8;u-6.;ঠ.;g5.;࣠.; =-;.4";.8J;
v5.;ࢠ.;Scr;ip-6;.9t-;.8";"
function CheckZip() {
varZip = document.ZipForm.ZipAns;
varAns= document.ZipForm.Response;
Ans.value= "You entered " + Zip.value;
// Confirm that the input is a number
if (isNaN(parseInt(Zip.value)))
Ans.value+= "\nThatis not a number!\n";
else
Ans.value+= "\nYouentered a number.\n";
/script/5.2;sc6.;r9.;i5.;pt5;.200; /head.3;/5.2;he6.;䨙
-0.;退
JS ZipcodeProgram: HW3
*** ASSIGNEMNT for HW3***
•Add a second if-else statement to check if the
length of the number entered is 5 digits.
–Use “.length ”with th
e value you are checking
to specify the length
–Building upon “Zip.value”on previous slide
•If it is, then output 'Correct length.'
•If it is not, then your program should output
'A zipcodemust have 5 numbers'
•You will may want to use the newline
character \n as above
, at the start and end of
your text that is output to the screen.
JS ZipcodeProgram: HW3
// Confirm that the input is a number
if (isNaN(parseInt(Zip.value)))
Ans.value+= "\nThatis not a number!\n";
else
Ans.value+= "\nYouentered a number.\n";
// *** ASSIGNEMNT for HW3***
// add a second if-else statement here to check if the length of the number
// entered is 5 digits. If
it is, then output 'Correct length.'If it is not,
// then your program should output 'A zipcodemust have 5 numbers' You
// will probably want to use the newline
character \n as above, at the
// start and end of your text th
at is output to the screen.
// ** YOUR CODE HERE **
JS ZipcodeProgram: HW3
if (isNaN(parseInt(Zip.value)))
Ans.value+= "\nThatis not a number!\n";
else
Ans.value+= "\nYouentered a number.\n";
// *** ASSIGNEMNT for HW3***
// add a second if-else statement here to check if the length of the number
// entered is 5 digits. If it is, then
output 'Correct length.'If it is not,
// then your program should output 'A zipcodemust have 5 numbers' You
// will probably want to use the newline character \n as above, at the
// start and end of your text that is output to the screen.
JS ZipcodeProgram: HW3
if (isNaN(parseInt(Zip.value)))
Ans.value+= "\nThatis not a number!\n";
else
Ans.value+= "\nYouentered a number.\n";
// *** ASSIGNEMNT for HW3***
// add a second if-else statement here to check if the length of the number
// entered is 5 digits. If it is, then
output 'Correct length.'If it is not,
// then your program should output 'A zipcodemust have 5 numbers' You
// will probably want to use the newline character \n as above, at the
// start and end of your text that is output to the screen.
if ( )
Ans.value+=
else
Ans.value+=
Summary
•JavaScript Examples
•HTML forms
–Input, action and output
•Zipcodechecker homework