-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2eu.js
More file actions
43 lines (34 loc) · 1.07 KB
/
script2eu.js
File metadata and controls
43 lines (34 loc) · 1.07 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const numberA=document.querySelector('.numberA')
const numberB=document.querySelector('.numberB')
const btncount=document.querySelector('.btncount')
const results=document.querySelector('.results')
const input=document.querySelector('input')
function euclideanAlgorithm(a, b) {
// Make sure a and b are positive integers
a = Math.abs(a);
b = Math.abs(b);
while (b !== 0) {
const remainder = a % b;
a = b;
b = remainder;
}
return a;
}
const funccheck=()=>
{
let numbera=numberA.value
let numberb=numberB.value
const respond=euclideanAlgorithm(numbera,numberb)
if(numbera!=='' && numberb!=='')
{
results.textContent=`Największy wspólny dzielnik liczba ${numbera} i ${numberb} to ${respond}`
numberA.style.borderColor="white"
numberB.style.borderColor='white'
}else if(numbera==='' && numberb==='')
{
results.textContent='Podaj liczby dla, których chcesz wyznaczyć NWD'
numberA.style.borderColor="red"
numberB.style.borderColor='red'
}
};
btncount.addEventListener('click', funccheck);