JS Arrays | Sololearn: Learn to code for FREE!

+1

JS Arrays

Fluffy Pancakes 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. /* I find JavaScript maddening at this point, but I refuse to give up. Can someone please help me to understand what the error or omission is here? Thank you. */

1/30/2022 9:54:44 PM

Tahiti🌍Castillo

11 Answers

New Answer

+4

Hope this code helps: https://code.sololearn.com/c25O9R8EM58M/?ref=app

+7

Tahiti🍷Castillo , I did not remember whole description of the task. I see your code is correct. You just need to change [fluffy pancakes] in '.....' single inverted rather than double inverted. Because your array of breakfast indexes has breakfast items in '.......' and not "......" #change done on line 16 check out the solution in case if gets solved. https://code.sololearn.com/cYW64L1Wxbl8/?ref=app

+2

Solomoni Railoa Thank you for this solution. They haven’t yet covered < for let …. in > at the point where I am in the JS tutorial, but it’s a concept I’ve seen outside of SoloLearn. It’s very helpful to see how it can be used to solve this task. Thank you!

+2

You're welcome Tahiti🍷Castillo . You can use the normal for loops like for (let i = 0; i < breakfast.length; i++){ breakfasts[i]; } to achieve the array printing part. I think Lesson 18.1 of JS course covers for loop concepts, similar to this simple one. You can also use for (i = 0; i < breakfast.length; i++){ breakfasts[i]; } Yes, you're right, the forLoop I've left in the previous solution is a concept found outside SoloLearn. I have no access to the Fluffy Pancakes code practice since I have no PRO subscription. Please do tell me if the solution works.

+1

It seems that my code isn’t uploading. Trying again here. https://code.sololearn.com/chqRRoU6oOuc/?ref=app

+1

I tried messing around with you code using kotlin I broke down how you can use it to write yours in java now all you need to do is find out how to replace the index ..with what ever .. https://code.sololearn.com/cCtZg8Iy1mL6/?ref=app

+1

Ion Kare Thank you for sharing this. 😵‍💫 I see I have a lot more studying to do. Kotlin is on my list of languages to learn, but your demo is actually my first look at Kotlin. Also, I’m working with JavaScript. Did you mean to reference Java? Or JavaScript? Thanks again.

+1

Javascript , but I started to learn javascript but those semi Colin's xD

+1

Solomoni Railoa I will revisit 18.1 Thank you. I tried your code and it gave an error. I updated the code bit, which shows the same error given in the Code Coach. https://code.sololearn.com/chqRRoU6oOuc/?ref=app

+1

Shivani 📚✍ Thank you for pointing this out. I hadn’t even noticed the single vs double quotes. I will make that update. Thanks!

+1