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 trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Functions Change the Flow of a Program

Teacher Russell
Teacher Russell
16,873 Points

function practiceGame() { }

This is just to practice some of the things we've learned so far, if anyone has any tips or suggestions:) Lots of problems, including getting the html to appear first....not sure how to make things run in what order. I also tried to document.write the greeting to the html but it always called the function first, no what I did.

https://codepen.io/HanLong45/pen/qXxMoq?editors=0010

Teacher Russell
Teacher Russell
16,873 Points

Oh my goodness. Thank you. I forgot about that. The first thing I made after a handful of hours of studying javascript:) I've learned so much since than. I should update that, in a big way.

2 Answers

Tsenko Aleksiev
Tsenko Aleksiev
3,819 Points

Hi there! I think the problem of loading the js before the html is because of the codepen.io I mean that if you are using some IDE, you should put the link to the js files at the end of the HTML, right before the closing body tag. Because HTML starts reading / loading from top to bottom, this way you will be sure that your page is going to load first aka show the HTML and after that it will execute the js file. In codepen.io I think to get things done you should have an aditional code specialy written for the loading. Why not try

window.onload = function //the name of the function

and the prompt for the name and confirmation put in a function, which you are going to call with the windows.onload?

You are missing a .toUpperCase so a user can type "yes" in any for they like e.g "YES , YeS , Yes"

var playerName = prompt("Please type your name here"); playerName += ("! Are you ready to play? Type yes"); var goOnTry = prompt(playerName); if (goOnTry. === "yes") { //PUT A .toUpperCase AND CHANGE TO ==="YES" beginQuiz(); }

Also to make it easier for others to read the code it would be a good idea to place this section at the top of your code as it's the first top be executed by the browser.

Happy coding :)