Programming in Javascript
Q1. JavaScript must be written in mixed case
a. true
b. false
Q2.
/*
This is a test
This is only a test!
/
a. Is a valid HTML comment
b. Is a valid JavaScript comment
c. Is a valid comment in both HTML and JavaScript
d. Is not a valid comment in HTML or JavaScript.
Q3. In XHTML, the script tag must be in upper case.
a. true
b. false
Q4. //This is a test — this is only a test!
a. Is a valid HTML comment
b. Is a valid JavaScript comment
c. Is a valid comment in both HTML and JavaScript
d. None of the above
Q5. In HTML, tags can be upper, lower, or mixed case.
a. true
b. false
Q6. The following is a legal variable name:
BigDog
a. true
b. false
Q7. The following is a legal variable name:
biGdoG
a. true
b. false
Q8. Given:
function test(x,y) {
window.alert(‘x=’+x+’, y=’+y);
}
var i = 10;
var j;
test(i,j);
What would the result be?
a. An alert box with the message x=10, y=
b. An alert box with the message x=10, y=undefined
c. An alert box with the message x=10, y=0
d. An error box
Q9. Which of the following would cause an alert box to pop up when called?
a. test()
window.alert(‘This is a test’);
b. test() {
window.alert(‘This is a test’);
}
c. function test() {
alert(This is a test);
}
d. function test() {
window.alert(‘This is a test’);
}
Q10. The following is a legal variable name:
This is a test
a. true
b. false
Q11. Given:
function test(x,y) {
window.alert(‘x=’+x+’, y=’+y);
}
test(10);
What would the result be?
a. An alert box with the message x=10, y=?
b. An alert box with the message x=10, y=
c. An alert box with the message x=10, y=undefined
d. Nothing
Q12. Javascript is always enabled in browsers.
a. true
b. false
Q13. To use an event handler, you must first define it.
a. true
b. false
Q14. To submit a form without the user clicking a submit button, use:
a. onsubmit()
b. submit()
c. click()
d. Can’t be done!
Q15. Given:
City:
State:
Which will move the cursor to the state textbox when the page loads
a. var s_box = document.getElementById(‘state’);
s_box.focus();
b. var s_box = document.getElementById(state);
s_box.focus();
c. state.focus();
d. set focus on state
Q16. When validating a form, which return should be used?
a. yes/no
b. true/false
c. 1/0
d. 1/-1
Q17. Which event handles a submit button?
a. submit
b. onsubmit
c. onmousedown
d. onclick
Q18. Every event handler has a variable that is used to reference the event.
a. true
b. false
Q19. Constructor functions and regular functions use a completely different structure.
a. true
b. false
Q20. Javascript provides _____ predefined functions.
a. many
b. a few
c. no
Q21. A mouseout event happens when a user releases a mouse button after clicking a button on a page.
a. true
b. false
Q22. Constructor functions and regular functions use the same basic structure.
a. true
b. false
Q23. A mouseout event happens:
a. When the mouse hovers over certain items in the window.
b. When the mouse hovers over certain items in the window and then is moved to another area.
c. When any mouse button is released.
d. When the left mouse button is released.
Q24. Given:
function test(x) {
var out;
if (x < 5) {
out = ‘Less Than 5’;
}
else if (x > 10) {
out = ‘Greater than 10’;
}
else {
out = ‘Between 5 and 10, inclusive!’;
}
document.write(out+'<br />’);
}
test(3);
test(6);
test(11);
What will be displayed in the browser window?
a. Greater than 10
Between 5 and 10, inclusive!
Less Than 5
<b
</b
b. Less Than 5
Between 5 and 10, inclusive!
Greater than 10
<b
</b
c. Nothing, it has errors
d. Nothing, it will display in a popup.
Q25. Given x == 1 , what does == mean?
a. Is x equal to 1
b. Set x equal to 1
c. Set x equal to 2
d. Is x equal to 2