I’ve been trying to create a game with Javascript and HTML5, but I can’t check the ScoreValue text field (attached to the Score variable) in order to see if the player has won or lost.
Scoring:
var Contacts;
var Contacts2;
var Contact;
var Contact2;
var Contact3;
var Contact4;
var Contact5;
var Contact6;
var Contact7;
var Contact8;
var Score;
var Score = 1;
var Contact = function(){
document.getElementById('Alien1').style.display="none";
document.getElementById('ScoreValue').innerHTML = Score++;
};
var Contact2 = function(){
//for(var Contacts = 1; Contacts > 2;)
document.getElementById('Alien2').style.display="none";
document.getElementById('ScoreValue').innerHTML = Score++;
};
var Contact3 = function(){
//for(var Contacts = 1; Contacts > 2;)
document.getElementById('Alien3').style.display="none";
document.getElementById('ScoreValue').innerHTML = Score++;
//Contacts++
};
var Contact4 = function(){
//for(var Contacts = 1; Contacts > 2;)
document.getElementById('Alien4').style.display="none";
document.getElementById('ScoreValue').innerHTML = Score++;
//Contacts++
};
var Contact5 = function(){
//for(var Contacts = 1; Contacts > 2;)
document.getElementById('Alien5').style.display="none";
document.getElementById('ScoreValue').innerHTML = Score++;
//Contacts++
};
var Contact6 = function(){
//for(var Contacts = 1; Contacts > 2;)
document.getElementById('Alien6').style.display="none";
document.getElementById('ScoreValue').innerHTML = Score++;
//Contacts++
};
var Contact7 = function(){
//for(var Contacts = 1; Contacts > 2;)
document.getElementById('Alien7').style.display="none";
document.getElementById('ScoreValue').innerHTML = Score++;
//Contacts++
};
var Contact8 = function(){
//for(var Contacts = 1; Contacts > 2;)
document.getElementById('Alien8').style.display="none";
document.getElementById('ScoreValue').innerHTML = Score++;
//Contacts++
};
Score checking so far:
//timer = setTimeout(LevelChangeCheck,1000000);
//var LevelChangeCheck = function(){
if (document.getElementById('ScoreValue').value == "8"){
if(confirm("Hello, do you like cake?")){
alert("BLAH")
};
};
//};
Note- This is a deliberately small sample (the full page is 1000+ lines of mixed code), so if you want to review the full thing visit hordeattack.tumblr.com
The way you are writing may work in some browsers and not in others. To make it more reliable you should use library such as Jquery. Using jquery you can do it in following way.