0

For my Javascript assignment I have to make a slot machine.

The one part I can't get is adding my totalCredits Variable to my textfield.

It just puts the variable beside the credits instead of adding them. (want to add 30 + 2 but I get 302)

I have tried parseFloat and parseInt both give me "ReferenceError: invalid assignment left-hand side"

This is the function

    function checkForWin() {

     if (bet1 == true && symbols[rng1].color == symbols[rng2].color && symbols[rng2].color == 
        symbols[rng3].color && symbols[rng1].color == symbols[rng3].color) {

document.getElementById("message").innerHTML = "Same Color You Win 2 Credits";
            totalCredits = totalCredits + 2;

            parseInt(document.getElementById('credits').value) = totalCredits;
            console.log(totalCredits);

     };

Code : https://jsfiddle.net/Socha/ndLn73bw/

3
  • What does this line do ? parseInt(document.getElementById('credits').value) = totalCredits; Commented Oct 14, 2015 at 6:23
  • Do it like this totalCredits = parseInt(totalCredits) + 2; and document.getElementById('credits').value = totalCredits; Commented Oct 14, 2015 at 6:24
  • You can't redeclare the variable by putting it on the left hand side. You've solved your own problem. Commented Oct 14, 2015 at 6:31

1 Answer 1

1

Change it as below

            total = parseInt(totalCredits) + 2;

            document.getElementById('credits').value = total;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.