Why this code not working in Sololearn? | Sololearn: Learn to code for FREE!

0

Why this code not working in Sololearn?

function main(increase) { const prices = [98.99, 15.2, 20, 1026]; for (i = 0; i < prices.length; i++) { prices[i] = prices[i] + increase; } return console.log(prices); }; main(Number(prompt()));

js

10/15/2021 1:37:58 PM

Антон Дектярёв

7 Answers

New Answer

+4

+2

Антон Дектярёв Sololearn JavaScript projects are running on Node JS so prompt will not work here. You have to use readLine() function Also you are returning console.log which is a default function in JS You have to return array. But actually you don't have to return anything just print prices If you print using console.log then why you need to return that. Do this: function main() { const prices = [98.99, 15.2, 20, 1026]; var increase = parseInt(readLine()); for (var i = 0; i < prices.length; i++) { prices[i] = prices[i] + increase; } console.log(prices); }; //main(Number(prompt()));

+1

Антон Дектярёв Because you have wrongly returned value and also no need to call main function You didn't declared i also

+1

This code working correctrly in VS Code.

+1

Антон Дектярёв But Sololearn is not VS Code

+1

But its working on me . https://code.sololearn.com/Wg5UJMvi9jNy/?ref=app

0

Samialloh Yes it is working here but will not work in Lesson. Try there not in code playground.