+ 10
I need help with the store manager question
function main() { var increase = parseInt(readLine(), 10); var prices = [98.99, 15.2, 20, 1026]; //your code goes here let newPrices = []; for (let i = 0; i < prices.length; i ++) { var n = prices[i] + increase; newPrices.push(n); console.log(newPrices); }; };
20 Antworten
+ 18
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
var incPrice = prices.map(cur => cur + increase);
console.log(incPrice);
}
+ 8
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
for (i=0; i<4; i++){
prices[i] = increase + prices[i];
}
console.log(prices)
}
+ 4
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
i=0;
for(;i<prices.length;)
{
prices[i] += increase;
i++;
}
console.log(prices);
}
There you go.
+ 4
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
prices[0] = prices[0] + increase ;
prices[1] = prices[1] + increase ;
prices[2] = prices[2] + increase ;
prices[3] = prices[3] + increase ;
console.log (prices);
}
basic but good
+ 1
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
const result=[];
for (let i = 0; i < prices.length; i += 1) {
result.push(prices[i] += increase)
}
console.log(result);
}
+ 1
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
var newPrices = prices.map(x => x + increase)
console.log(newPrices)
}
+ 1
//Sololearn expected output: [ 107.99, 24.2, 29, 1035 ]
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
function newPrizes(x) {
return x + increase;
}
console.log(prices.map(newPrizes));
}
+ 1
For my code
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
for (var i = 0; i > prices.length; i++) {
var result = prices[i] + increase
prices[i] = result
}
console.log(prices)
}
+ 1
We should explain the code if somebody is stuck rather than just sharing the answer. Users will need to understand concepts to begin a development career. This is an older post but leaving this here for people looking for the answer.
I paste the code into Notepad++ files and comment each line to make sure I understand it. Here is what I have in my notes.
function main() { // Initializes the MAIN function
var increase = parseInt(readLine(), 10); // Creates a variable called INCREASE and assigns user input as the value
var prices = [98.99, 15.2, 20, 1026]; // Creates an array called PRICES and assigns 4 values
for (let i = 0; i < prices.length; i++) { // A for loop that runs as long as the value of i is less than the length of the PRICES array
prices[i]+=increase; // Adds int INCREASE value to each index of the PRICE array
}
console.log(prices); // Outputs the new PRICE value for each price assigned to the PRICES variable
0
Check this out :
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
prices.forEach((item, index, arr) => {
arr[index] = item + increase
})
console.log(prices)
}
0
You can use push method in array, check this out :
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
let result = [];
for (let i = 0; i < prices.length; i++) {
result.push(prices[i] + increase);
}
console.log (result);
}
0
Here is my solution :
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
var i = prices.length - 1;
while(i >= 0){
prices[i] = prices[i] + increase;
i--;
}
console.log(prices);
}
0
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
var newPrices = [];
for( i = 0; i < prices.length; i++){
newPrices.push(prices[i] + increase);
}
console.log(newPrices)
}
0
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
for(i=0;i<prices.length;i++){
prices[i]=prices[i]+increase
}
console.log(prices);
}
0
If you want to be even more specific, you can make sure that your code still works if you decide to add more arguments into the prices array.
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
var x = prices.length
for (i=0; i<x; i++){
prices[i] = increase + prices[i]
}
console.log(prices)
0
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
for (i=0; i<4; i++){
prices[i] = increase + prices[i];
}
console.log(prices)
}
0
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
var newPrices=prices.map(myFunction)
function myFunction(num) {
return num+increase;
}
console.log(newPrices);
}
0
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
i=0;
for(;i<prices.length;)
{
prices[i] += increase;
i++;
}
console.log(prices);
}
0
I want to Try
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
for (i=0; i<= prices.length-1; i++){
var prevPrice =prices[i];
var newPrice = prevPrice + increase ;
prices[i]= newPrice;
}
//var incPrice = prices.map(cur => cur + increase);
//console.log(incPrice);
console.log(prices);
}
- 8
Check those links.
Next time try to use the search bar, most of the time your questions has already been asked, and so answered.
https://www.sololearn.com/Discuss/2621003/?ref=app
https://www.sololearn.com/Discuss/2612434/?ref=app