+ 6
You commented out the loop and you need it for all prices. You have a "sum" but don't have anything saying what that should do.
5th Dec 2022, 8:12 AM
Ausgrindtube
Ausgrindtube - avatar
+ 5
Let me ask you a few questions, that hopefully send you in the right direction. How are you going to add the numbers? How do you loop through an array? (Hint: look at that lesson) Can you add numbers in a loop?
5th Dec 2022, 8:29 AM
Ausgrindtube
Ausgrindtube - avatar
+ 3
First you have array, then you manually take values with index, imagine you have 1000 items in array will you do the same? Then you log console.log(prices[i]) where you define i variable? i is undefined Then you make object constructor function, not regular function, and inside it you set values and one method, then you call this constructor function(used to create objects) inside itself with wrong syntax, syntax we use for regular function what can lead to many bugs if used in this way. Then in unfinished line you try to do something with value of x.price, you will have x.prices if you look at line: this.prices = prices But as I said you are creating new object from constructor inside constructor body and try to access it, this is very wrong, if you need to use object constructors for this task please read lections again, you didn't understand how to use it. Here are amazing resource about it: https://www.theodinproject.com/lessons/node-path-javascript-objects-and-object-constructors
5th Dec 2022, 8:58 AM
PanicS
PanicS - avatar
+ 2
To fix your code we will need to solve problem from beggining,and share with you completed code, this won't help you, follow resource i posted it dive very deep in explaining constructors. Also this can be solved without constructors, you just need regular function what accept given array, and increase amount, then inside function you return new changed array. You can use any loop(for, while) or array methods like forEach, then add this increase amount to price.
5th Dec 2022, 9:03 AM
PanicS
PanicS - avatar
+ 2
Just add newPrices.push(prices[i]) Inside loop. If you wanna learn please read documentation about this topic before moving on to next lections. Every project here on sololearn are about things we learned before, and it is test of your understanding.
6th Dec 2022, 4:35 PM
PanicS
PanicS - avatar
+ 1
If you are doing sololearn project, your goal inside it is not to use object constructors. Goal is to use array methods, you learned in lections before Startup code look something like this: function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; var newPrices = []; //your code goes here // in tip you got information to use loop // you can use any, loop for/while, but for is better in this case because we dont need to create variable outside of loop for(let i = 0; i < prices.length; i++) { // how can you add new item to array? What method we use, use this method and you are solved problem } // then you return or log result, i used console log console.log(newPrices); } check this to find method you need to use: https://www.w3schools.com/js/js_array_methods.asp
5th Dec 2022, 6:35 PM
PanicS
PanicS - avatar