JAVASCRIPT · ОСНОВЫ · LESSON 20
Bottom line: counting points
Array, function and condition · about 18 minutes
Learning with progressRead the summary for free. To save the work, log in to the account.
Type the code yourself
Type an example manually. Check the names, brackets and signs.
function total(scores) {
let sum = 0;
for (const score of scores) {
sum += score;
}
return sum;
}
const scores = [2, 3, 4];
const result = total(scores);
if (result >= 8) {
console.log("Победа");
}Open the editor for class workSolve it yourself
Write the function total(Zscores): fold the points with the loop for...of and return the amount. For the array [1, 2, 5] output «Готово» if the result is not less than 8.
The answer is hidden. Use similar examples from the lesson notes.
Opening up your homework