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 trialThanitsak Leuangsupornpong
7,490 PointsAny thing wrong here,it doesn't show text when I type list,other word?
I mean in the teacher video,when type correct it will appear the text but mine,need to break out the loop first.
MY HTML CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Search the Store</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>Search the Store</h1>
<script src="js/search.js"></script>
</body>
</html>
MY JAVASCRIPT CODE
var inStock = [ 'apples', 'eggs', 'milk', 'cookies', 'cheese', 'bread', 'lettuce', 'carrot', 'broccoli', 'pizza', 'potato', 'crackers', 'onion', 'tofu', 'frozen dinner', 'cucumber'];
var search;
function print(message) {//Function print out paragraph to the webpage
document.write( '<p>' + message + '</p>');
}
while(true){
search=prompt('Search the name of the product in our store.Type "list" to show the product name.Type "exit" to out the question');
search=search.toLowerCase();
if(search===('exit') ){
break;
}else if(search===('list') ){
print(inStock.join(', '));
}else{
if(inStock.indexOf(search)>-1){
print('Yes! we have '+search+' in the store!');
}else{
print('Nope '+'we don\'t have '+search);
}
}
}
2 Answers
Michael Daniel
2,404 PointsAre you using Safari? I've noticed the same issue with Safari on my Mac. I have to break out of the prompt before it will amend the HTML changes to the page.
I've noticed this same issue on a few other classes, so it's not just this lesson. It appears to be an issue with how Safari handles prompts. Safari appears to hold off on changes to the page until the prompt is resolved.
I've tested my code with Chrome for Mac, and it correctly prints the HTML changes to the page correctly while the prompt is still active.
Nicolás Carrasco-Stevenson
Courses Plus Student 5,668 PointsI just copied your code to my workspace and the document changes based on my input so I'm not entirely sure what is your problem. I'm using Google Chrome BTW.
Thanitsak Leuangsupornpong
7,490 PointsMy problem is when I type the list it should appear the text immediately to the webpage, but my it doesn't.It need to break out,then appear the text.I didn't use google chrome
Thanitsak Leuangsupornpong
7,490 PointsThanitsak Leuangsupornpong
7,490 PointsYes,yes I that the problem! how to fix it?