Extenza-Academy / WebDev-100_2021-Q1

24 Lessons, 12 Weeks, Get Started as a Web Developer
2 stars 0 forks source link

2.4.6. Assignment #67

Closed mserykh closed 3 years ago

mserykh commented 3 years ago

Assignment

Loop an Array

Instructions

Create a program that lists every 3rd number between 1-20 and prints it to the console.

TIP: use a for-loop and modify the iteration-expression

Rubric

Criteria Exemplary Adequate Needs Improvement
Complete solution is presented Partial solution is presented Solution with bugs is presented
mserykh commented 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);
dev-experience commented 3 years ago

@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);
dev-experience commented 3 years ago

@mserykh Another thing. Your solution doesn't match the instructions. Please do another version no. 2 that matches (no functions, just for loop).

mserykh commented 3 years ago

@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);
mserykh commented 3 years ago

@dev-experience just with a loop:

 for (let i = 1; i <= 20; i++) {
  if (i % 3 === 0) {
    console.log(i);
  }
}
dev-experience commented 3 years ago

@mserykh check out the TIP and try again:

TIP: use a for-loop and modify the iteration-expression

mserykh commented 3 years ago
for (let i = 3; i <= 20; i += 3) {
  console.log(i);
}
dev-experience commented 3 years ago

@mserykh Great!

It's important to carefully read the tasks and follow all the tips.

dev-experience commented 3 years ago

@mserykh test