Closed mserykh closed 3 years ago
const printEveryThird = (i) => {
if (i % 3 === 0) {
console.log(i);
}
}
const getNumbers = (n) => {
for (let i = 1; i <= n; i++) {
printEveryThird(i);
}
}
getNumbers(20);
@mserykh
// The function does two things at the same time. And the name is misleading anyways
const printEveryThird = (i) => {
if (i % 3 === 0) {
console.log(i);
}
}
// Please remove redundant parenthesis. They are noisy.
const getNumbers = (n) => {
for (let i = 1; i <= n; i++) {
printEveryThird(i);
}
}
// What do you mean by `getNumbers`? Why it's not `printEveryThird()`?
getNumbers(20);
@mserykh Another thing. Your solution doesn't match the instructions. Please do another version no. 2 that matches (no functions, just for
loop).
@dev-experience please see rewritten:
const isThird = i => i % 3 === 0;
const printEveryThird = n => {
for (let i = 1; i <= n; i++) {
if(isThird(i)) {
console.log(i);
}
}
};
printEveryThird(20);
@dev-experience just with a loop:
for (let i = 1; i <= 20; i++) {
if (i % 3 === 0) {
console.log(i);
}
}
@mserykh check out the TIP and try again:
TIP: use a for-loop and modify the iteration-expression
for (let i = 3; i <= 20; i += 3) {
console.log(i);
}
@mserykh Great!
It's important to carefully read the tasks and follow all the tips.
@mserykh test
Assignment
Loop an Array
Instructions
Create a program that lists every 3rd number between 1-20 and prints it to the console.
Rubric