0% found this document useful (0 votes)
3 views2 pages

Javascript Test Answers

The document contains answers to a JavaScript test, including multiple choice, fill in the blanks, true/false questions, and short answer sections. It also includes code writing exercises demonstrating user input handling and conditional statements. Overall, it serves as a comprehensive answer sheet for assessing JavaScript knowledge.

Uploaded by

instainsta34012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Javascript Test Answers

The document contains answers to a JavaScript test, including multiple choice, fill in the blanks, true/false questions, and short answer sections. It also includes code writing exercises demonstrating user input handling and conditional statements. Overall, it serves as a comprehensive answer sheet for assessing JavaScript knowledge.

Uploaded by

instainsta34012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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')
}

You might also like