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()));
7 Answers
+ 4
Ok thanks.
+ 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
0
Samialloh
Yes it is working here but will not work in Lesson. Try there not in code playground.