0

Undefined line in result

Hi, can you please explain me why result is OK, but second line "undefined" There fore I cannot finish this exercise. Thanks function main() { var percent = parseInt(readLine(),10); console.log(salaryIncrease(percent)); } var salaries = [3000, 7000, 5000, 15000]; const salaryIncrease = percent => {var total =0; salaries.forEach(item => { total += (item/100)*percent; }); console.log(total); }

11th Feb 2022, 8:09 AM
Zdeněk Helebrand
Zdeněk Helebrand - avatar
2 Answers
+ 3
Function salaryIncrease() does not return anything, it only log <total> to console. When you do this in main() console.log( salaryIncrease( percent ) ); There be nothing to log cause salaryIncrease() returned nothing (undefined). Solution: Either just call salaryIncrease() cause it already is logging <total>, or return <total> from salaryIncrease() and log the return value in main()
11th Feb 2022, 9:15 AM
Ipang
+ 1
Your output is identical to this: console.log(console.log(total));
11th Feb 2022, 10:05 AM
Solo
Solo - avatar