Why this code not working in Sololearn? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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()));

15th Oct 2021, 1:37 PM
Антон Дектярёв
Антон Дектярёв - avatar
6 Answers
+ 4
Ok thanks.
15th Oct 2021, 2:10 PM
Антон Дектярёв
Антон Дектярёв - avatar
+ 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()));
15th Oct 2021, 1:55 PM
A͢J
A͢J - avatar
+ 1
Антон Дектярёв Because you have wrongly returned value and also no need to call main function You didn't declared i also
15th Oct 2021, 1:39 PM
A͢J
A͢J - avatar
+ 1
This code working correctrly in VS Code.
15th Oct 2021, 1:45 PM
Антон Дектярёв
Антон Дектярёв - avatar
+ 1
Антон Дектярёв But Sololearn is not VS Code
15th Oct 2021, 1:51 PM
A͢J
A͢J - avatar
0
Samialloh Yes it is working here but will not work in Lesson. Try there not in code playground.
15th Oct 2021, 1:59 PM
A͢J
A͢J - avatar