57.3 Salary Rise | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

57.3 Salary Rise

Hi there What would the proper code with the for.each function be? Thanks function main() { var percent = parseInt(readLine(),10); var salaries = [3000, 7000, 5000, 15000]; let sum = 0; for (let i = 0; i < salaries.length; i++) { sum += salaries[i]; } console.log (sum * percent / 100) }

12th Feb 2022, 10:30 AM
Bball4Life
2 Answers
+ 4
salaries.forEach(i=>sum+=i);
12th Feb 2022, 11:21 AM
Solo
Solo - avatar
+ 1
sum=0 for (let i of salaries) sum += i; Do you mean about this?
12th Feb 2022, 11:03 AM
Jayakrishna 🇮🇳