Loops - Exercise 1

Question 1: List Positive Steps

Using a loop, return the integers from 1 through the supplied non-negative limit, inclusive.

Expected output: [1,2,3,4] (print this with console.log)

javascript

function listPositiveSteps(limit) {
  // Write your solution here
}

console.log(listPositiveSteps(4));

Question 2: List Even Steps

Return the even integers from 0 through the supplied non-negative limit, inclusive.

Expected output: [0,2,4] (print this with console.log)

javascript

function listEvenSteps(limit) {
  // Write your solution here
}

console.log(listEvenSteps(5));

Question 3: List an Inclusive Range

Return the integers from start to end inclusive. Return an empty array when start exceeds end.

Expected output: [3,4,5,6] (print this with console.log)

javascript

function listInclusiveRange(start, end) {
  // Write your solution here
}

console.log(listInclusiveRange(3, 6));

Question 4: List Descending Odd Numbers

Return the positive odd integers no greater than the non-negative start, in descending order.

Expected output: [5,3,1] (print this with console.log)

javascript

function descendingOddNumbers(start) {
  // Write your solution here
}

console.log(descendingOddNumbers(6));

Question 5: Sum an Inclusive Range

Return the sum of integers from start to end inclusive, or zero when start is greater than end.

Expected output: 14 (print this with console.log)

javascript

function sumInclusiveIntegerRange(start, end) {
  // Write your solution here
}

console.log(sumInclusiveIntegerRange(2, 5));

Question 6: Build Multiples

Return the first count positive multiples of the supplied number. Count is a non-negative integer.

Expected output: [3,6,9,12] (print this with console.log)

javascript

function buildFirstMultiples(number, count) {
  // Write your solution here
}

console.log(buildFirstMultiples(3, 4));

Question 7: Calculate a Factorial

Return the factorial of a non-negative integer using a loop. The factorial of 0 is 1.

Expected output: 120 (print this with console.log)

javascript

function factorialWithLoop(number) {
  // Write your solution here
}

console.log(factorialWithLoop(5));

Question 8: Sum the First Squares

Return the sum of the squares from 1 through the non-negative limit.

Expected output: 14 (print this with console.log)

javascript

function sumFirstSquares(limit) {
  // Write your solution here
}

console.log(sumFirstSquares(3));

Question 9: Build a Number Staircase

Return strings of one through count asterisks in an array. Count is non-negative.

Expected output: ["*","**","***"] (print this with console.log)

javascript

function buildAsteriskStaircase(count) {
  // Write your solution here
}

console.log(buildAsteriskStaircase(3));

Question 10: Sum Odd Numbers to a Limit

Return the sum of positive odd integers no greater than the non-negative limit.

Expected output: 16 (print this with console.log)

javascript

function sumOddNumbersToLimit(limit) {
  // Write your solution here
}

console.log(sumOddNumbersToLimit(7));