JavaScript Test — Answer Sheet
Multiple Choice Answers:
1. B
2. B
3. C
4. B
5. C
6. B
7. C
8. B
9. A
10. C
Part A — Fill in the Blank:
1. \n
2. null
3. assign, compare
4. true, false
5. NOT, false
Part B — True/False:
6. False — OR returns true if at least one condition is true.
7. False — Variable names are case-sensitive and treated as different.
8. False — AND returns true only when both conditions are true.
9. True
10. False — var is only needed when declaring the variable.
Part C — Short Answers:
11. a=true, b=true, c=false, d=false, e=true
12. Line 1 asks the user for input and stores it. Line 2 checks if the value equals 'Sarah'.
13. Bugs fixed:
- prompt should be lowercase
- comparison should use ==
- missing quote and wrong Else capitalization
Corrected code:
var guess = prompt('Enter password:')
if (guess == 'Firewall') {
alert('Access Granted')
} else {
alert('Incorrect')
}
14. Steps: true, false, false, true, true, true
Final alert: true
15. null means no value. It occurs when a user clicks Cancel in prompt().
Part D — Code Writing:
16.
var age = prompt('Enter your age:')
if (age == null) {
alert('No age entered')
} else if (age >= 18) {
alert('You are eligible to vote')
} else {
alert('You are not eligible yet')
}
17.
if (firstConfirm) {
var secondConfirm = confirm('Do you really want to leave?')
if (secondConfirm) {
alert('Goodbye')
} else {
alert('Thanks for staying')
}
} else {
alert('Thanks for staying')
}