Array | Sololearn: Learn to code for FREE!

-2

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.

1/12/2021 8:10:18 AM

Priya Ghosh

49 Answers

New Answer

+3

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

+3

@Sajid Ali https://www.sololearn.com/learning/1024/1239/1774/1

+3

Priya Ghosh you need to reset the code and then add this: breakfasts[index]= "Fluffy Pancakes"; console.log(breakfasts);

+1

Please try to solve it and provide us with the link to your attempt.

+1

Priya Ghosh see my previous answer and follow the link

+1

breakfasts[index] = 'Fluffy Pancakes'; console.log(breakfasts);

+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.

+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.

+1

Anup Varma learn java then learn Android studio

+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

+1

Priya Ghosh Sajid Ali’s code wont work for your code coach problem because it does not take any input.

+1

Caleb can you give me code cach link..

+1

Sajid Ali no i have not seen it. you need to ask Priya Ghosh

+1

Priya Ghosh if you face again problme,, share link of code cach... I will try..to solve!

+1

Priya Ghosh need a code cach page link.. Where is question wrote by sololearn!

+1

Priya Ghosh just send the code that the problem gives you to begin with, please.

+1

@ caleb this is the start code - function main() { var breakfasts = ['Cinnamon Doughnuts', 'Fluffy Pancakes', 'Waffles', 'Granola', 'Chorizo Burrito', 'French Toast']; var index = parseInt(readLine(), 10) //replace the corresponding element by "Fluffy Pancakes" //output the menu to the console }

+1

Its a pro package.. 😬

+1

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

+1

Priya Ghosh newArray(wrong) And new Array (correct) Check ur code