Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1if (score >= 80) { return "A"; } | AA default return at the end of the function that covers every score the earlier branches did not catch. | |
| 2return "C"; | BIf the score is 80 or more, the function returns "A" straight away and stops running. | |
| 3A function can return a different value from each branch of an if and else. | Cfunction gradeFor(score) { if (score >= 50) { return "Pass"; } else { return "Fail"; } } | |
| 4Put a default return after the if statements so every other case still gets a value. | DThere is no default return. A score below 80 skips the if and the function returns undefined. | |
| 5function gradeFor(score) { if (score >= 80) { console.log("A"); } } | EThe branch uses console.log instead of return, so the function gives nothing back. It returns undefined. | |
| 6function gradeFor(score) { if (score >= 80) { return "A"; } } | Fif (score >= 80) { return "A"; } if (score >= 65) { return "B"; } return "C"; |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
if (score >= 80) { return "A"; } — A function can use if and else to make a decision, then return a different value from each branch. A default return at the end covers every other case.function gradeFor(score) {
if (score >= 50) { return "Pass"; }
return "Fail"; }function gradeFor(score) {
if (score >= 80) { return "A"; }
return "B"; }function gradeFor(score) {
if (score >= 80) { return "A"; }
return "C"; }function gradeFor(score) {
if (score >= 50) { return "Pass"; }
else { return "Fail"; } }function gradeFor(score) {
if (score >= 80) { return "A"; }
return "C"; }