w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Subtraction is not working on a variable

First, correct the line with:

TrysLeft = -1;

by:

TrysLeft -= 1;

Next:

You can use a closure to keep the current value of the variable each time the function is called:

var TrysLeft = 3;

function Check() {
var Viewer = document.getElementById("Viewer");
    if (Viewer.value == Num) {
    alert("Correct");
    } else {
    `TrysLeft -= 1;`
    alert("Sorry you got the combo wrong! You have " + TrysLeft + " Trys
left before the combo is reset");
    }
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.