Vous êtes sur la page 1sur 1

15/05/2019 March 2019

BMIS 32152 – Web Techniques and Applications


Tutorial Lecture 7 – JS: Control Statement I

1. Which of the following is not a valid variable name? Why?


a. %ofTax
b. eightball_8
c. 12footage
d. pageNumber1200
2. Write four JavaScript statements that each multiply 1 to variable m, which contains a number.
3. In the following line, the word writeln performs a task or action in the script. What it is called?

document.writeln("Hello World");

4. Write a JavaScript statement to accomplish each of the following tasks:


a) Declare variables total and w.
b) Assign 1 to variable w.
c) Assign 0 to variable total.
d) Add variable w to variable total, and assign the result to variable total.
e) Print "The total is: ", followed by the value of variable total.
5. Identify and correct the errors in each of the following segments of code. [Note: There may be more than
one error in each piece of code; unless declarations are present, assume all variables are properly declared
and initialized.]
a. if ( age >= 65 );
document.writeln( "Age greater than or equal to 65" );
else document.writeln( "Age is less than 65" );
b. var x = 1, total;
while ( x <= 10 )
{ total += x; ++x; }
c. var x = 1; var total = 0;
While ( x <= 100 )
total += x; ++x;
d. var y = 5;
while (y> 0 )
{ document.writeln( y );
++y;

Submit your work after the class ends

Vous aimerez peut-être aussi