EmeraldX Posted February 10, 2015 Share Posted February 10, 2015 Hello world! I am new to programming, and I need help with an assignment. I do not think my professor left us intentionally in the dust, but I believe he just hasn't covered this yet. Anyways, we are creating a text adventure with html5/javascript and one of the objectives is to keep score when you click on an option. My options are go north, south, east, and west. On the first click to these areas you get 5 points, otherwise you only get 1 point. So far I only have this part of the code for score done: function displayScore() { alert ("Score"); } document.write('<span id="score">Your score is '+score+'</span>'); This was in thanks to a fellow classmate, but I want to know how to finalize the code and know what each of these lines do. I do not necessarily need a popup to show the score, it could even be in a text field tag. I'm sorry if I'm not using correct terminology, but the help would be greatly appreciated! Thanks! Link to comment Share on other sites More sharing options...
Ingolme Posted February 10, 2015 Share Posted February 10, 2015 Learn to access and manipulate elements of the page using the DOM. Here's the tutorial page for that: http://www.w3schools.com/js/js_htmldom_methods.asp Continue reading from there. document.write() won't get you very far. It can put new things on the page, but it won't change what's already there. Link to comment Share on other sites More sharing options...
EmeraldX Posted February 10, 2015 Author Share Posted February 10, 2015 Learn to access and manipulate elements of the page using the DOM. Here's the tutorial page for that: http://www.w3schools.com/js/js_htmldom_methods.asp Continue reading from there. document.write() won't get you very far. It can put new things on the page, but it won't change what's already there. Now would this have to go into the score function or could this be it's separate entity? I'm sorry, I'm a very slow learner when it comes to programming. Link to comment Share on other sites More sharing options...
dsonesuk Posted February 10, 2015 Share Posted February 10, 2015 To keep score you might want to look into http://www.w3schools.com/html/html5_webstorage.asp Link to comment Share on other sites More sharing options...
EmeraldX Posted February 10, 2015 Author Share Posted February 10, 2015 To keep score you might want to look into http://www.w3schools.com/html/html5_webstorage.asp I have this so far: function displayScore() { var textField = document.getElementbyID("score"); textField.style.color="blue"; if (localStorage.clickcount) { localStorage.clickcount = 0(localStorage.clickcount) + 5; } else { localStorage.clickcount = count + 1; } } I have been given no errors with my html document but it isn't working. I feel like I am still missing something. Link to comment Share on other sites More sharing options...
Ingolme Posted February 11, 2015 Share Posted February 11, 2015 localStorage won't display anything visually. It's purely for saving data so that it's available in the future. Your function has some problems: 1. Variable count is not defined anywhere. 2. This expression is a syntax error because of that stray zero: 0(localStorage.clickcount) + 5; 3. The textField variable is not being used anywhere. You're setting its text color to blue, but doing nothing else with it. Is your function being called from anywhere else in the page? Link to comment Share on other sites More sharing options...
EmeraldX Posted February 11, 2015 Author Share Posted February 11, 2015 (edited) I'm sorry this topic can be closed. The solution has been found. Edited February 12, 2015 by EmeraldX Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now