syllabus
syllabus copied to clipboard
Add more in-class exercises to JS2 Week 3
Which module(s) and week(s) does this change effect? Module(s): JS2 Week(s): 3
What is the work that needs to be done?
On this week of the syllabus
https://syllabus.codeyourfuture.io/js-core-2/week-3/lesson#exercise-1
We don't have a huge amount of in-class exercises to explain what we're trying to teach
This ticket should add 1-2 new exercises for each part of the lesson that teachers can call on.
Each of these exercises should have attached solutions, in a tab on the page
Why is this work important to do?
Exercises are the primary way that we should be teaching and having lots of them will increase the chance that students understand what they're being taught
Here's the exercise (with solutions). Tasks
- [ ] remove solutions and make comments exercise steps
- [ ] put exercises into syllabus page https://github.com/CodeYourFuture/syllabus/blob/master/docs/js-core-2/week-3/lesson.md
- [ ] include solutions tab
- [ ] add exercises to JS2 W3 Classwork Repo https://github.com/CodeYourFuture/Table-of-Contents/blob/main/README.md
// Your partner has been asked to write a function
// this function takes a score and returns a string
// based on the score
// 1 = winner
// 2 or 3 = runner-up
// 4 or more = loser
//The input will always be a positive integer
// Your partner has written the following function
function p(s) {
if (s == 1) {
return "winner";
} else if (s === 2 || s === 3) {
return "runner-up";
} else if (s >= 4) {
return "loser";
}
return "loser";
}
// Refactor the function to use clearer variable names
function getPlace(score) {
if (score == 1) {
return "winner";
} else if (score === 2 || s === 3) {
return "runner-up";
} else if (score >= 4) {
return "loser";
}
return "loser";
}
// Refactor the function to use fewer comparison operators
function getPlace(score) {
if (score == 1) {
return "winner";
} else if (score <= 3) {
return "runner-up";
} else if (score >= 4) {
return "loser";
}
return "loser";
}
// Refactor the function to only use necessary if/else statements
function getPlace(score) {
if (score < 2) return "winner";
if (score <= 3) return "runner-up";
return "loser";
}
// Refactor the function to use an arrow function
const getPlace = (score) => {
if (score < 2) return "winner";
if (score <= 3) return "runner-up";
return "loser";
};
// Refactor the function to use a switch statement
function getPlace(score) {
switch (score) {
case 1:
return "winner";
case 2:
case 3:
return "runner-up";
default:
return "loser";
}
}
// Refactor the function to use a ternary operator
const getPlace = (score) =>
score < 2 ? "winner" : score >= 3 ? "runner-up" : "loser";
// Questions to answer:
// which solution is the most readable? Why? Is there one right answer?
// there are some subtle differences between the solutions, can you spot them?