chrisy brown chrisy brown - 4 months ago 12
Javascript Question

Javascript - if statement error

Wondering if someone can steer me into the right direction, I'm trying to use Javascript to make a little game to help me learn. Essentially I declare all my variables which I want to change outside of my function so they act global, which works in the code but the if statement seems to be not proving successful, I cant seem to correct this as tutorials point to my code as correct, please see code below;

var Refresh;
Refresh = "InActive";

var Counter;
Counter = 0;

var StartTime;

function StartGame() {
var StartDate;
StartDate = new Date();
StartTime = d.getTime();
Refresh = "Active";

function FunctionB1() {
if (Refresh == "Active"){
document.getElementById("Bean1").style.display = "None";
Counter ++;
document.getElementById("BeanCount").innerHTML = Counter + " Out of 150";


You need to change d.getTime(); to StartDate.getTime(); to reflect the change in variable name.

function StartGame() {
StartTime = new Date().getTime();
Refresh = "Active";

JSFiddle: Solution

Edited to include Xufox's improvement.