Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren0
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); }
2 Antworten
+ 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()
+ 1
Your output is identical to this:
console.log(console.log(total));