JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Useful Array Methods

Sam Morpeth
Sam Morpeth
8,042 Points

I can't even get the prompt box to appear.

I can't even get the prompt box to appear when trying to replicate the code from this video. I tried following the video all the way to the end to see if anything would change.

I've attached a snapshot of the prompt box code: https://w.trhou.se/gy9nj2i46u

I'm using Firefox if that helps.

Steven Parker
Steven Parker
173,537 Points

Kevin Gates — good reply, you should post it as an answer instead of a comment. That makes it available for voting and potential selection as "best answer". If I were a mod, I'd happily promote it for you.

Kevin Gates
Kevin Gates
14,700 Points

Steven Parker : thanks. I just started helping out on Community recently. Must've posted it in the wrong spot. I moved it if you'd still like to upvote it. :)

Steven Parker
Steven Parker
173,537 Points

Kevin Gates — Welcome to the community! You may find helping addictive — if you check the forum points on my profile, you can tell I've done it a bit myself. :wink:

I was surprised to discover how much I enjoyed helping folks, and that I often learned new things myself while doing it.

And perhaps Sam Morpeth will find your reply helpful and judge it "best answer".

2 Answers

Kevin Gates
Kevin Gates
14,700 Points

It is your use of quotes. You start your string with double quotes. When you refer to "list" and "quit", you use double quotes, which essentially means you are ending the string and then causing bad syntax. You could update it to this instead:

search = prompt("Search for a product in our shop. Type 'list' to show all of the products and 'quit' to exit");

OR use the escape character which is \

search = prompt("Search for a product in our shop. Type \"list\" to show all of the products and \"quit\" to exit");

OR you can reverse the use of quotations:

search = prompt('Search for a product in our shop. Type "list" to show all of the products and "quit" to exit');

I've also heard on a few podcasts people are suggesting using back-ticks "" for this purpose, because then you can use regular double/single quotes inside without issue. It also helps later with template literals shenanigans (${}`) that I haven't quite gotten the hang of yet. But they only take back-ticks because JS occasionally likes to be evil.

Sam Morpeth
Sam Morpeth
8,042 Points

It was very helpful. Kind of embarrassing to make such a small mistake after spending so many hours with the language. Oh well!

Kevin Gates
Kevin Gates
14,700 Points

Backticks are helpful for what is called Template Literals or Template Strings: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Template Literals are not supported in IE11 or lower: https://caniuse.com/#feat=template-literals

Therefore, unless you're using something like Babel to compile your code, then if you need to have your application work on IE 11, you should use standard quotes.

However, all that said, the purpose of this course is to teach the basics and not presume them. Knowing these intricate parts are helpful for understanding the language and how it works. Later when one learns ES6 +, you can find all the neat shortcuts :)