-
Notifications
You must be signed in to change notification settings - Fork 0
/
newChal.js
29 lines (29 loc) · 777 Bytes
/
newChal.js
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
function twiceAsOld(dadYearsOld, sonYearsOld) {
// set output to int
let output = 0;
// write if statement to find out if son already half as old as dad
if(dadYearsOld == sonYearsOld * 2) {
return output;
} else if(dadYearsOld > sonYearsOld * 2) {
// write loop to go up/down and add one year to output
for(i = 0; i < 100; i++) {
dadYearsOld++;
sonYearsOld++;
if(dadYearsOld == sonYearsOld * 2) {
output = i+1;
//retuyr output
return output;
}
}
} else if(dadYearsOld < sonYearsOld * 2) {
for(i = 0; i < 100; i++) {
dadYearsOld--;
sonYearsOld--;
if(dadYearsOld == sonYearsOld * 2) {
output = i+1;
return output;
}
}
}
}
console.log(twiceAsOld(35, 7));