+ 7
You are working on a Store Manager program, which stores the prices in an array. You need to add functionality to increase the
@sololearn
62 odpowiedzi
+ 41
You need to tag JavaScript and code coach instead.
This problem "store manager" is very simple, you need to increase each items of the array. The following code will be helpful.
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-1;i++){
prices[i]=prices[i]+increase;
}
console.log(prices);
}
+ 20
Why is there prices.length-1 and not just prices.length? What does it do? Im confused 🤷♀️ I know it makes it flexible in case adding a new price but in what way?
+ 10
Justyna Dabrowska yes we can simply write price.length but loop should be
for(var i=0;i<prices.length;i++){}
Not
for(var i=0;i<=prices.length;i++){}
Simply condition part of the loop should be i<price.length
+ 9
bruh thats all what you need
console.log(prices.map(x=>x+increase));
+ 7
Simple way to solve :
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
//var prices1=0;
for(var i=0;i<4;i++){
prices[i] = prices[i]+increase;
}
console.log(prices);
}
+ 4
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-1;i++){
prices[i]=prices[i]+increase;
}
console.log(prices);
}
+ 4
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-1;i++){
prices[i]=prices[i]+increase;
}
console.log(prices);
}
+ 4
I cant remember [i] ever explained but ok
+ 3
Why is there prices.length-1 and not just prices.length? What does it do? Im confused 🤷♀️ I know it makes it flexible in case adding a new price but in what way?
+ 3
Puedes realizarlo usando el método map().
const increment = prices.map(e => e + increase);
console.log(increment);
+ 3
# Use map function
console.log(prices.map((p) => {
return p+increase;
}))
+ 1
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] += increase;
}
console.log(prices);
}
+ 1
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//ваш код
array = [];
for(n=0; n<prices.length; n++){
array.push(prices[n] + increase);
}
console.log(array);
}
+ 1
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
prices.forEach(inc => console.log (inc+increase))
}
why this is not passing the testcase even though its correct
+ 1
Tried for a long time and finally had this one:
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
var newPrices = [];
for (let num of prices){
let pri = num += increase;
newPrices.push(pri);
}
console.log(newPrices)
}
+ 1
function main() {
let increase = parseInt(readLine(), 10);
let prices = [98.99, 15.2, 20, 1026];
//your code goes here
for(i=0; i<prices.length; i++) {
prices[i] += increase;
}
console.log(prices);
}
+ 1
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-1;i++){
prices[i]=prices[i]+increase;
}
console.log(prices);
}
Good Luck
+ 1
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
for (var x = 0;x < prices.length;x++)
{
prices[x]= prices[x]+increase;
}
console.log(prices);
}
+ 1
function main() {
var increase = parseInt(readLine(), 10);
var prices = [98.99, 15.2, 20, 1026];
//your code goes here
console.log("[ "+parseFloat(prices[0]+increase)+", "+parseFloat(prices[1]+increase)+", "+parseFloat(prices[2]+increase)+", "+parseFloat(prices[3]+increase)+" ]");
}
+ 1
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-1;i++){
prices[i]=prices[i]+increase;
}
console.log(prices);
}