You are on page 1of 3

1ST Summative Exercises

A. 1. 2. 3. 4. 5. 6. 7. 8. 9. Write document.write(True); if the statement is true, and document.write(Error); if the statement is false. It is advisable to not use simple assignments in a conditional expression, because the assignment can be confused with equality when glancing over the code. true If you need to use an assignment in a conditional expression, a common practice is to put additional parentheses around the assignment. true In general, it is a good practice to always use block statements, especially in code involving nested if statements. true Comparison operators can be used in conditional statements to compare values and take action depending on the result true The comparison operators determine if the an operand meet the given condition. False (Two operands, not one) Javascript represents false by a boolean false. true The return value of the modulus operator maintains the sign of the first operand. true JavaScript has arithmetic operators that does not operate very similarly to other languages. false (does operate very similarly to other languages, such as PHP, C or C++) Global variables will be deleted as soon as the function is completed. false (Global variables will be deleted when you close the page. empty until a value is assigned using the equal sign.) 11. A comment is a named placeholder for a value. false (A variable) 12. Comments dont have value. false (Comments do have value, though; theyre very useful for explaining things to human readers of your script.) 13. Initializing a variable means setting a variable equal to some value. true 14. If the comment begins with two forward slashes, it is called a multiple-line comment. false (single-line comment) 15. When your browser can interpret JavaScript, it ignores comments. True B. Give the translation of the following operations and evaluate if whether True, False, or cannot be determined. IF a=5; b=6; c=7; and d=5 Meaning 1. a == c 2. a===d 3. a!==d 4. b >= a 5. b = (d > 0) ? -d : d 5 is equal to 7 5 is exactly equal to 5 5 is not equal to 5 6 is greater than or equal to 5 if d is greater than zero, assign -d to b; otherwise, assign d to b FALSE TRUE FALSE TRUE Cannot be determined Evaluation 10. When you declare variables with the var keyword, they will automatically have a value of one. false (After the declaration, it will remain

1. ALERT BOX when clicking a picture

<html> <head> <title></title> <script type="text/javascript"> function MyNumberPicker(number) { alert("You clicked on " + number); } </script> </head> <body> <center> <a href="javascript:MyNumberPicker(1)"><img src="1.gif" width="40" height="41" border="0" alt="1"></a> <a href="javascript:MyNumberPicker(2)"><img src="2.gif" width="40" height="41" border="0" alt="2"></a> <a href="javascript:MyNumberPicker(3)"><img src="3.gif" width="40" height="41" border="0" alt="3"></a> </center> </body> </html> 2. PROMPT BOX: get your name, when you clicked a picture <html> <head> <title></title> <script type="text/javascript"> function MyNumberPicker(number) { myname = prompt("What's your name?", ""); alert("Hey " + myname + ", you picked number " + number + "."); } </script> </head> <body>

<center> <a href="javascript:MyNumberPicker(1)"><img src="1.gif" width="40" height="41" border="0" alt="1"></a> <a href="javascript:MyNumberPicker(2)"><img src="2.gif" width="40" height="41" border="0" alt="2"></a> <a href="javascript:MyNumberPicker(3)"><img src="3.gif" width="40" height="41" border="0" alt="3"></a> </center> </body> </html>

You might also like