Vous êtes sur la page 1sur 3

22/05/2019 March 2019

BMIS 32152 – Web Techniques and Applications


Tutorial Lecture 8 – JS: Control Statement II

1. Find the error in each of the following segments of code and correct the error(s). [Note: There may be more
than one error]:
a) for ( x = 100, x >= 1, ++x )
document.writeln( x );

b) The following code should print whether the integer value is odd or even:
switch ( value % 2 )
{
case 0:
document.writeln( "Even integer" );
case 1:
document.writeln( "Odd integer" );
}

c) The following code should output the odd integers from 19 to 1:


for ( x = 19; x >= 1; x += 2 )
document.writeln( x );

d) The following code should output the even integers from 2 to 100:
counter = 2;
do
{
document.writeln( counter );
counter += 2;
} While ( counter < 100 )

2. What would the browser display if the following script were executed?
<script type = "text/javascript">
<!--
for ( var i = 0; var i < 5; var i++ )
document.write( "X" );
//-->
</script>

3. What would the browser display if the following script were executed?
<script type = "text/javascript">
<!--
for ( var i = 0; i < 5; i++ )
document.write( "O" );
//-->
</script>

Submit your work after the class ends


22/05/2019 March 2019

4. What would the browser display if it executed the following script?


<script type = "text/javascript">
<!--
var i = 0;
do
{
document.write( "#" );
i++;
} while ( i > 5 );
//-->
</script>

5. What would the browser display if it executed the following script?


<script type = "text/javascript">
<!--
for ( var count = 1; count <= 10; ++count )
{
if ( count == 5 )
break;
}
document.writeln( count );
//-->
</script>

6. What would the browser display if it executed the following script?

<script type = "text/javascript">


<!--
for ( var count = 0; count < 10; ++count )
{
if ( count == 5 )
continue;
}
document.writeln( count );
//-->
</script>

Submit your work after the class ends


22/05/2019 March 2019

7. What does the following script do?

<!DOCTYPE html>

<!-- Exercise 8.5: ex08_05.html -->


<html>
<head>
<meta charset = "utf-8">
<title>Mystery</title>
<script>
document.writeln( "<table>" );

for ( var i = 1; i <= 7; i++ )


{
document.writeln( "<tr>" );

for ( var j = 1; j <= 5; j++ )


document.writeln( "<td>(" + i + ", " + j + ")</td>" );

document.writeln( "</tr>" );
} // end for

document.writeln( "</table>" );

</script>
</head><body />
</html>

Submit your work after the class ends