-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (23 loc) · 771 Bytes
/
script.js
File metadata and controls
28 lines (23 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function gcd(a, b) {
while (b > 0) {
const remainder = a % b;
a = b;
b = remainder;
}
return a;
}
function calculateGCD() {
const num1 = parseInt(document.getElementById("num1").value);
const num2 = parseInt(document.getElementById("num2").value);
if (isNaN(num1) || isNaN(num2) || num1 < 0 || num2 < 0) {
alert("Please enter valid positive integers.");
return;
}
const gcdResult = gcd(num1, num2);
document.getElementById("result").textContent = `The GCD of ${num1} and ${num2} is: ${gcdResult}`;
}
function clearInputs() {
document.getElementById("num1").value = "";
document.getElementById("num2").value = "";
document.getElementById("result").textContent = "";
}