Highscore variable not working on game [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am currently developing a game using Phaser, and trying to implement a system to save the highscore from the current score. It isn't working for some reason and I don't know why, it seems to not be changing the highscore variable based on the current score.
I have put the simple game on Jsfiddle with the code here: https://jsfiddle.net/zpy8wLqf/
This is what I tried for the highscore variable.
highscore=0;
var currentscore;
if(this.currentscore>highscore){
highscore =this.currentscore;
}
The textures are not there, but that shouldn't be a problem.

thats because your check only runs on state start, try putting the check inside the reset
reset: function() {
if(this.currentscore>highscore){
highscore =this.currentscore;
}
// Start the 'main' state, which restarts the game
begin.state.start('adventure');
}

Related

javascript not loading image error::ERR_FILE_NOT_FOUND [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
Hey guys i am building dice roller website using random in javascript but after setting attributes for dice image i am getting file not found error.Images are stored like images/dice.png
your actualy seting the image's source to the str randomImg rather then the variable's value what you want to do is remove the "" that make it a string and use the variable
so the last line of the js would look like document.querySelectorAll[0].setAttribute('src',randomImg)

How to update value in realtime database in Firebase using JS [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
This is what my database looks like:
My question is how to I decrement the value of FIELD11 i.e. "4" in my realtime database in Firebase using javascript, everytime I click on DECREMENT Button on my html page it should decrement this value and get updated in realtime database. Thank You
I recommend you use a Firebase transaction.
When working with data that could be corrupted by concurrent modifications, such as incremental counters, you can use a transaction operation.
Example:
https://firebase.google.com/docs/database/web/read-and-write#save_data_as_transactions

ReactJS how to persist state in cookies [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Below is sample example for counter but i have to maintain the state after page is refree.For example i will increment the counter to 10 and next time when my page refreshes the page should start with 10 instead of 1.
Can anyhow guide me regarding this.
If you want to use cookies JS-cookie is really handy. Setting and retrieving cookie is really easy.
Use localStorage for that.
In your action handler do:
let counter = window.localStorage.getItem("counter");
window.localStorage.setItem("counter ", ++counter);
Then in your componentDidMount do:
let counter = window.localStorage.getItem("counter");
this.setState("counter", counter);

Script turns page white [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
so this is a very very simple script. however... every time i run it inside chrome, by the "onmouseover" my entire page turns white. i have no idea why?
this is the script. it was way larger. but i seems to fail at this point...
already tried with other measurements. always the same.
function open(){
document.getElementById("gtext").style.marginTop = "37vh";
document.getElementById("gpic").style.marginTop = "37vh";
document.getElementById("gvid").style.marginTop = "37vh";
document.getElementById("gaudio").style.marginTop = "37vh";
}
maybe someone here can help me.
thanks.
Here my Pen:
http://codepen.io/anon/pen/RarJVR
Try renaming your function to something else like e.g. openMenu
Sounds like you need to debug your code (are you asking the community to do it?). For starters, opacity can only take number values (not vh):
if(document.getElementById("gtext").style.opacity == "37vh") {

Keeping Score of quiz in javascript website [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
We are creating a website in which homework (with about 10 multiple choice questions) will be graded. Each question is on their own HTML page. How do we tally the overall grade of the homework, while keeping track of each multiple choice question? (Deduct .33 points twice if wrong, then tally that score to a total score for the homework)
You need to have some state to persist the answers. There are a number of options including:
save the answer to the server for each question
save the answer to localStorage
save the answer in a cookie
save the answer in the URL as a query parameter
If you prefer to stay client side, I suggest using localStorage. It is a key-value store with some limitations on size but it should be a good fit for your problem.
My approach would be to store the answer into localStorage for each question. On the final page, I would load all the answers and perform the calculation for points.
MDN: localStorage

Categories