CC-04: For Loops and Conditionals

with Carmen Salas • 2024/10/08

Review

yesterday's CC

Code Challenge

  1. Write a function named countFromOne that takes in an integer argument, and console.logs all the integers from 1 up to the given integer.

const countFromOne = (x) => {
  for (let i = 1; i <= x; i++) {
    console.log(i)
  }
}

// tests
// countFromOne(10);
// countFromOne(1);
  1. Write a function named countEveryOdd that takes in an integer argument, and console.logs all the odd integers from 1 up to the given integer, including the given integer.

  1. Write a function isNegative that takes in a number parameter and returns true if the number is a negative value and false if the number is a positive value.

  1. Write a function named betweenFiveAndTwenty that takes in an integer parameter, and checks whether a given integer is within 5 and 20. It returns true if it is and false if not.

  1. Write a function named sumOfThreeOrFive that returns the sum of all the multiples of 3 or multiples of 5 from 1 to 1000, exclusive.

  1. Write a function named isAllLowerCase that takes in a string parameter, and returns true or false if the string consists of only lowercase letters.

BONUS

  1. Write a function named countMultiplesOfFive that takes in an array of integers and returns the number of integers in the array that are multiples of five.

Last updated