with correct answers 100 %
All JavaScript mistakes will be pointed out automatically by the computer and cause the code to not run.
- Correct Answer False
Strict mode causes more errors in JavaScript, but can be helpful for debugging. - Correct Answer True
A common bug in JavaScript is a type mismatch. - Correct Answer True
Manual testing is more work than automated testing initially, but saves time in the long run. - Correct
Answer False
Find the bug:
line 1: var investment=1000; //investment is $1,000line 2: var interestRate = .1; //interest is 10% (or
10/100 or .1)line 3: var goal = 1500; //goal is $1500
line 4: var nbrYears = 0;
line 5: //while my investment is less than the goal, keep counting the yearsline 6: while (investment <
goal) {line 7: var interestEarned = investment * interestRate;line 8: investment + interestEarned;line 9:
nbrYears++;line 10: }line 11: console.log("It took "+nbrYears+" years to reach the goal"); - Correct
Answer The bug is on line 8. The investment will never increase because the result of the addition is not
being set to the variable investment.
Find the bug:
line 1: var investment=1000; //investment is $1,000line 2: var interestRate = .1; //interest is 10% (or
10/100 or .1)line 3: var goal = 1500; //goal is $1500
line 4: var nbrYears = 0;
line 5: //while my investment is less than the goal, keep counting the yearsline 6: while (investment <
goal) {line 7: var interestEarned = investment * interestRate;line 8: investment += interestEarned;line 9:
nbryears++;line 10: }line 11: console.log("It took "+nbrYears+" years to reach the goal"); - Correct
Answer The bug is on line 9. The variable nbryears is not the same as nbrYears because variables are
case sensitive. Therefore, the program will always say it took 0 years to reach the goal.
, Which of the following is NOT a debugging tool recommended by the JavaScript textbook used in class? -
Correct Answer Asking Siri
Error Propagation can always be prevented by returning a -1 value from a function. - Correct Answer
False
Exceptions break out of a section of code which cannot proceed as intended. - Correct Answer True
Which keyword is used to signify a section of code which should be executed following an exception? -
Correct Answer catch
A JavaScript programmer should never allow an unhandled exception. - Correct Answer False
Which of the following indicates a range of characters when used within square brackets?
to - Correct Answer -
Match the regular expression shortcuts with their meaning
1. \d
2. \w
3. \s
4. \D
5. \W
6. \S
7. \i
8. . - Correct Answer 1. any digit
2. alphanumeric
3. whitespace
4. Not a digit
5. nonalphanumeric
6. nonwhitespace