Tell us what’s happening:
Can someone explain why every says that the remainder of all inputs into isAFactor does not equal = true whenever i = 60? (60 is the least common multiple of 1/2/3/4/5) In this challenge it gives two numbers and you have to find the least common multiple of all numbers in the range. I have successfully created an array to do this. range = [ 1, 2, 3, 4, 5 ] in this case. I just don’t understand how I’m using the every method incorrectly. I know I have to be able to tick i up to check for the LCM but I hard set it to 60 in this example to try to figure out why the code does not work.
Your code so far
function smallestCommons(arr) {
//console.log(arr[1])
let range = [];
if(arr[0] > arr[1]){
let placeHolder = arr[0]
arr[0] = arr[1]
arr[1] = placeHolder
}
for(let i = arr[0]; i <= arr[1]; i++){
range.push(i)
}
console.log(range)
//myLength = arr.length
var i = 60
var isAFactor = (currentValue) => (currentValue % i) == 0
do{
var myStatus = range.every(isAFactor)
console.log(myStatus)
// i++;
} while (myStatus == false)
}
smallestCommons([5,1]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36
.
Challenge: Smallest Common Multiple
Link to the challenge: