# CC-04: For Loops and Conditionals

with Carmen Salas • 2024/10/08

* [Review](#review)
* [Code Challenge](#code-challenge)

## 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.

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

// tests
// countFromOne(10);
// countFromOne(1);
```

2. 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.

```js
const countEveryOdd = (x) => {
  for (let i = 1; i <= x; i+=2) {
    console.log(i)
  }
}

// tests
// countEveryOdd(11);
// countEveryOdd(6);
```

3. 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.

```js
const isNegative = (x) => {
  return (x < 0) ? true : false;
}

// tests
// console.log(isNegative(-1));
// console.log(isNegative(10));
// console.log(isNegative(0));
```

4. 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.

```js
const betweenFiveAndTwenty = (x) => {
  return (x >= 5 && x <= 20) ? true : false;
}

// tests
// console.log(betweenFiveAndTwenty(12));
// console.log(betweenFiveAndTwenty(5));
// console.log(betweenFiveAndTwenty(100));
```

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

```js
const sumOfThreeOrFive = () => {
  sum = 0;
  for (let i = 1; i < 1000; i++) {
    if (i%3 == 0 || i%5 == 0) {
      sum += i;
    }
  }
  return sum;
}

// test
// console.log(sumOfThreeOrFive());
```

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

```js
const isAllLowerCase = (str) => {
  for (let i = 0; i < str.length; i++) {
    asciiCode = str.charCodeAt(i);
    if (asciiCode == 32) { continue; }
    if (asciiCode < 97 || asciiCode > 122) { return false; }
  }
  return true
}

// test
// console.log(isAllLowerCase("hello")) //returns true
// console.log(isAllLowerCase("seven eleven")) //returns true
// console.log(isAllLowerCase("Seven eleven has the best slushies")) //returns false
```

### 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.

```js
const countMultiplesOfFive = (arr) => {
  return arr.filter((x) => x%5 == 0).length;
}

// test
// console.log(countMultiplesOfFive([1,2,3,4,5,6,7,8,9,10])) // returns 2
// console.log(countMultiplesOfFive([15,23,35,45,67])) // returns 3
// console.log(countMultiplesOfFive([2,6,14])) // returns 0
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://raffycastlee.gitbook.io/marcyannotes/codechallenge-curriculum/unit-1/20241008.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
