File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < title > Chapter 18: Exercise 1</ title >
5+ </ head >
6+ < body >
7+ < script >
8+ function writeTimesTable ( timesTable ) {
9+ var writeString ;
10+ for ( var counter = 1 ; counter <= 12 ; counter ++ ) { // error is here: counter <= 12, not counter < 12
11+ writeString = counter + " * " + timesTable + " = " ;
12+ writeString = writeString + ( timesTable * counter ) ;
13+ writeString = writeString + "<br />" ;
14+ document . write ( writeString ) ;
15+ }
16+ }
17+
18+ for ( var timesTable = 1 ; timesTable <= 12 ; timesTable ++ ) {
19+ document . write ( "<p>" ) ;
20+ writeTimesTable ( timesTable ) ;
21+ document . write ( "</p>" ) ;
22+ }
23+ </ script >
24+ </ body >
25+ </ html >
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < title > Chapter 18: Question 2</ title >
5+ </ head >
6+ < body >
7+ < form name ="form1 " action ="">
8+ < input type ="text " id ="text1 " name ="text1 " />
9+ < br />
10+ CheckBox 1< input type ="checkbox " id ="checkbox2 " name ="checkbox2 " />
11+ < br />
12+ CheckBox 1< input type ="checkbox " id ="checkbox1 " name ="checkbox1 " />
13+ < br />
14+ < input type ="text " id ="text2 " name ="text2 " />
15+ < p > < input type ="submit " value ="Submit " id ="submit1 " name ="submit1 " /> </ p >
16+ </ form >
17+ < script >
18+ function checkForm ( e ) {
19+ var elementCount = 0 ;
20+ var theForm = document . form1 ;
21+ while ( elementCount = < = theForm . length ) { // wrong operator
22+ if ( theForm . elements [ elementcount ] . type == "text" ) {
23+ if ( theForm . elements [ elementCount ] . value ( ) = "" )
24+ alert ( "Please complete all form elements" ) ;
25+ theForm . elements [ elementCount ] . focus ;
26+ e . preventDefault ( ) ;
27+ break ;
28+ }
29+ }
30+ }
31+
32+ document . form1 . addEventListener ( "submit" , checkForm ) ;
33+ </ script >
34+ </ body >
35+ </ html >
You can’t perform that action at this time.
0 commit comments