Sie sind auf Seite 1von 2

23/11/2017 Oct 2017

BMIS 32152 Web Techniques and Applications


Tutorial Lecture 7JavaScript: Control Statement Part I

1. Write JavaScript statements to accomplish each of the following tasks:


a. Assign the sum of x and y to z, and increment the value of x by 1 after the calculation. Use
only one statement.
b. Test whether the value of the variable count is greater than 10. If it is, print "Count is
greater than 10".
c. Decrement the variable x by 1, then subtract it from the variable total. Use only one
statement.
d. Calculate the remainder after q is divided by divisor, and assign the result to q. Write this
statement in two different ways.
2. Write a script including statements for variable declaration and assignment that will calculate and
print the sum of the integers from 1 to 10. Use the while statement to loop through the calculation
and increment statements. The loop should terminate when the value of x becomes 11.
3. What is the output of this following script?

<!DOCTYPE html>

<html>
<head>
<meta charset = "utf-8">
<title>Mystery Script</title>
<script>
var y;
var x = 1;
var total = 0;

while ( x <= 10 )
{
y = x * x;
document.writeln( "<p>" + y + "</p>" );
total += y;
++x;
}// end while

document.writeln( "<p>Total is " + total + "</p>" );


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

Submit your work in Edmodo in 1 week.


23/11/2017 Oct 2017

2. Which of the following JavaScript statements contain variables whose values are changed?
a. p = i + j + k + 7;
b. window.alert( "variables whose values are destroyed" );
c. window.alert( "a = 5" );
d. stringVal = window.prompt( "Enter string:" );

3. Given y = ax3 + 7, which of the following are correct JavaScript statements for this equation?
a. y = a * x * x * x + 7;
b. y = a * x * x * (x + 7);
c. y = (a * x) * x * (x + 7);
d. y = (a * x) * x * x + 7;
e. y = a * (x * x * x) + 7;
f. y = a * x * (x * x + 7);

4. Write a script that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers
separated by one space. Write the script using the following methods:
a. Using one document.writeln statement.
b. Using four document.write statements.

Submit your work in Edmodo in 1 week.

Das könnte Ihnen auch gefallen