Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGary Angarita
Full Stack JavaScript Techdegree Student 1,878 PointsNot sure what I'm doing wrong (I have included the code)
I tried using const instead of var but it crashes after I input a verb (my var activity prompt).
var name = prompt("Give me a food");
console.log(name);
var location = prompt("Give me a place");
console.log(location);
var activity = prompt("Give me a verb"); //HERE IS WHERE IT CRASHES
console.log(activity);
let message = `<p>I once ate a ${name} in ${location} while ${activity} down the road.</p>`;
console.log(message);
document.querySelector('main').innerHTML = message;
Mod edit: added markdown for code readability
1 Answer
Cameron Childres
11,820 PointsInteresting problem! It looks like this issue is stemming from the use of location
as a variable. If you change it to something else, such as place
, you should be good to go.
The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.
window object is at the top of the scope chain, so properties of the window.location object can be accessed without window.
I stumbled in to this answer by noticing the weird behavior of being sent to another page after the script runs. Looking at the URL I noticed that my answer to the second question was appended on to the end, then searched for documentation relating to that variable. I hope this helps!
Gary Angarita
Full Stack JavaScript Techdegree Student 1,878 PointsThank you! That was perfect! I've been stuck on this for two days and I almost (ALMOST) quit altogether. I figured if I was having this much trouble in the early-going then I wasn't going to make it. I really appreciate your help
Cameron Childres
11,820 PointsCameron Childres
11,820 PointsTry using the "markdown cheatsheet" linked below the comment box to make your code more readable, like this:
```javascript
code here
```