How to find LCM

Dear Team,

I want to find LCM, I try but got error.please help

What is the source of your algorithm?

Github

That’s kind of like if I told you I was building a bicycle and you asked where the instructions were and I said “on paper.”

I was hoping to see the algorithm so I could help you figure out why your blocks aren’t following it correctly.

Edit: ah, there they are below.

/*
author: PatOnTheBack
license: GPL-3.0 or later

Modified from:
    https://github.com/TheAlgorithms/Python/blob/master/maths/findLcm.py

More about LCM:
    https://en.wikipedia.org/wiki/Least_common_multiple

*/

‘use strict’

// Find the LCM of two numbers.
const findLcm = (num1, num2) => {
// If the input numbers are less than 1 return an error message.
if (num1 < 1 || num2 < 1) {
return ‘Please enter values greater than zero.’
}

// If the input numbers are not integers return an error message.
if (num1 !== Math.round(num1) || num2 !== Math.round(num2)) {
return ‘Please enter whole numbers.’
}

let maxNum
let lcm
// Check to see whether num1 or num2 is larger.
if (num1 > num2) {
maxNum = num1
} else {
maxNum = num2
}
lcm = maxNum

while (true) {
if (lcm % num1 === 0 && lcm % num2 === 0) break
lcm += maxNum
}
return lcm
}

export { findLcm }

Convert this onto block

1 Like

What are you using to code this? It’s not Thunkable X.

You missed a line (in bold).

Try to run this code.

this is kodular and you asked the same thing here -

I’m going to close this topic since you’re not using Thunkable. Hopefully someone on those other forums can help you.

I see you’ve also been warned by other forum moderators on those sites.

3 Likes