- 3

Array

The array you are given represents the menu of breakfast options available at the hotel. The Chef decided to replace one of the options with "Fluffy Pancakes". Write a program to take the index as input, replace the element with that index with "Fluffy Pancakes", and output the new menu to the console as an array. Sample Input 2 Sample Output [ 'Cinnamon Doughnuts', 'Waffles', 'Fluffy Pancakes', 'Chorizo Burrito', 'French Toast' ] The element with index 2 has been replaced in the output array. ----------------------- I have done this - function main() { var breakfasts = ['Cinnamon Doughnuts', 'Waffles', 'Fluffy Pancakes', 'Granola', 'Chorizo Burrito', 'French Toast']; var index = parseInt(readLine(), 10) //replace the corresponding element by "Fluffy Pancakes" //output the menu to the console document.write(arr[2]); } But it's not working.

12th Jan 2021, 8:10 AM
Priya Ghosh
Priya Ghosh - avatar
61 Antworten
+ 7
He guys , Here is the solution for this question function main() { var breakfasts = ['Cinnamon Doughnuts', 'Waffles', 'Granola', 'Chorizo Burrito', 'French Toast']; var index = parseInt(readLine(), 10) //replace the corresponding element by "Fluffy Pancakes" //output the menu to the console breakfasts[index] = "Fluffy Pancakes"; console.log(breakfasts); }
16th May 2021, 12:58 PM
Vivek Shyamsunder Gupta
Vivek Shyamsunder Gupta - avatar
+ 3
function main() { var breakfasts =new Array ['Cinnamon Doughnuts', 'Waffles', 'Fluffy Pancakes', 'Granola', 'Chorizo Burrito', 'French Toast']; var index = parseInt(readLine(), 10) breakfasts[index]= "Fluffy Pancakes"; console.log(breakfasts); } try this Bro : new array likhna tha
12th Jan 2021, 8:12 PM
Sajid Ali
Sajid Ali - avatar
12th Jan 2021, 8:03 PM
Priya Ghosh
Priya Ghosh - avatar
+ 2
Priya Ghosh you need to reset the code and then add this: breakfasts[index]= "Fluffy Pancakes"; console.log(breakfasts);
12th Jan 2021, 8:19 PM
Brain & Bones
Brain & Bones - avatar
+ 2
Hey Priya, It is solved in this way. Mine worked immediately :) ... function main() { var breakfasts = ['Cinnamon Doughnuts', 'Waffles', 'Granola', 'Chorizo Burrito', 'French Toast']; var index = parseInt(readLine(), 10) //replace the corresponding element by "Fluffy Pancakes" breakfasts[index]= "Fluffy Pancakes"; console.log(breakfasts); //output the menu to the console }
13th Sep 2021, 1:15 PM
Saleh Ghazimoradi
Saleh Ghazimoradi - avatar
+ 1
Read the second page of this lesson to learn how change specific indices of an array https://www.sololearn.com/learning/1239/ Also document.write does not work in NodeJS. Use console.log instead
12th Jan 2021, 8:27 AM
XXX
XXX - avatar
+ 1
anybody here ? can help me ?
12th Jan 2021, 8:31 AM
Priya Ghosh
Priya Ghosh - avatar
+ 1
Priya Ghosh see my previous answer and follow the link
12th Jan 2021, 8:33 AM
XXX
XXX - avatar
+ 1
breakfasts[index] = 'Fluffy Pancakes'; console.log(breakfasts);
12th Jan 2021, 9:22 AM
Avinesh
Avinesh - avatar
+ 1
Anyone here to solve it Please ?
12th Jan 2021, 11:46 AM
Priya Ghosh
Priya Ghosh - avatar
+ 1
Priya Ghosh Is it so hard to copy the whole code, save it on SL Playground and provide the link to it here? So is easier to help somebody.
12th Jan 2021, 11:52 AM
JaScript
JaScript - avatar
+ 1
JaScript Okay sure will do.
12th Jan 2021, 11:55 AM
Priya Ghosh
Priya Ghosh - avatar
+ 1
Priya Ghosh i believe you misunderstand the problem. you are suppost to replace whatever item the input says with Fluffy Pancakes so to do that you must add this. do not add it to your code. restart the challenge and add it. breakfasts[index]= "Fluffy Pancakes"; if it does not work. show me your attemped AND the code they give you originally.
12th Jan 2021, 12:10 PM
Brain & Bones
Brain & Bones - avatar
+ 1
Priya Ghosh Your code output : no ouput Reason : you define code under the function ,,,which anywhere not called , hence output is : no output or blank Your Function will be working with web-coding,, whenever in Html make a button with onclick=main() .. When you click button it will be work And try this... :) https://code.sololearn.com/cGcNShE9q9Ab/?ref=app
12th Jan 2021, 7:08 PM
Sajid Ali
Sajid Ali - avatar
+ 1
@Sajid Ali Sure Let me try it once.
12th Jan 2021, 7:40 PM
Priya Ghosh
Priya Ghosh - avatar
+ 1
@Osama Deep I have tried first and then when I'm facing problem I requested them and of course I should ask to my friends here. I don't need your "statement". I hope you will understand right!!.
12th Jan 2021, 7:45 PM
Priya Ghosh
Priya Ghosh - avatar
+ 1
Priya Ghosh Sajid Ali’s code wont work for your code coach problem because it does not take any input.
12th Jan 2021, 7:47 PM
Brain & Bones
Brain & Bones - avatar
+ 1
Caleb can you give me code cach link..
12th Jan 2021, 7:47 PM
Sajid Ali
Sajid Ali - avatar
+ 1
Sajid Ali no i have not seen it. you need to ask Priya Ghosh
12th Jan 2021, 7:49 PM
Brain & Bones
Brain & Bones - avatar
+ 1
@Caleb it's not working
12th Jan 2021, 7:51 PM
Priya Ghosh
Priya Ghosh - avatar