Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/code-challenges/code-challenges-003-010.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,26 @@ multiDimensionalSumOfSeveralArrayVariationReduce([[3, 2], [1], [4, 12]]);

/**
* Q005: Test divisors of three
* You will be given 2 parameters: a low and high number.
* Your goal is to print all numbers between low and high, and for each of these numbers print whether or not the number is divisible by 3.
* If the number is divisible by 3, print the word "div3" directly after the number.
*/

function testDivisors(low, high) {
// we'll store all numbers and strings within an array
// instead of printing directly to the console.
let output = [];

for (let i = low; i <= high; i++) {
// simply store the current number in the output array
output.push(i);

// Check if the current number is evenly divisible by 3
if (i % 3 === 0) output.push('div3');
}

// return all numbers and strings.
return output;
}

testDivisors(2, 10);