CC-03: For Loops
with Carmen Salas • 2024/10/07
For Loops
What is an expression? An expression is any valid unit of code that resolves to a value.
For Loop Structure
for ([initial expression], [condition expression], [increment expression]) {
[statement/s]
}A for loop repeats until the condition expression evaluates to false.
While Loop Structure
while ([condition expression]) {
[statement/s]
}Code Challenge
Write a function named
countToTenthat console.logs all the integers from 1 to 10.
Write a function named
countUpFromOnethat takes in an integer argument, and console.logs all the integers from 1 up to the given integer.
Write a function named
countDownFromNthat takes in an integer argument, and console.logs all the integers from the given integer to 1.
Write a function named
countEveryEventhat takes in an integer argument, and console.logs all the even integers from 1 up to the given integer, including the given integer.
Write a function named
countEveryOddthat takes in an integer argument, and console.logs all the odd integers from 1 up to the given integer, including the given integer.
BONUS
Write a fucntion named
countEvensthat takes in an array of integers and returns the number of integers in the array that are even numbers.
Last updated