Ive attempted to make a factorial. The code below should return 24 (4x3x2x1) however it actually returns 12.
const fact = (no) => {
let no2 = no;
if (no > 1) {
no--;
no2 = no2 * no;
}
console.log(no2);
}
fact(4);
Doh! Id confused if with while
const fact = (no) => {
let no2 = no;
while (no > 1) {
no--;
no2 = no2 * no;
}
console.log(no2);
}
fact(4);