0

The problem I am having is inside my if statements, the .clicks() do not work. I need i button to be clicked and rerun the script but it isnt working. The SetTimeout(start,5000) helps it repeate but makes the script run several times at once.

document.getElementById('sound-toggle').onclick = function() {

    var startingBet = 5;
    startingBet = parseFloat(startingBet);



    document.getElementById('bet-bt').onclick = function () {
            function start() {

            //show if it is getting chip amount
            //var rr = document.getElementById('bet-rb-2').innerHTML; //neerdsa classs s3elec5to9r
            //var rr = document.getElementById('bet-rb-2').innerHTML; 
            //

              setTimeout(start,5000);

            //select the result of the spin
            var result = document.getElementById('result-text').innerHTML;
            alert(result.length);
            if (result.length == 5) { //lost


                alert('lost');
                 //document.getElementById("bet-bt").click();
                break;
            } else if ( result.length == 4) {  //won
                alert('won');
                //document.getElementById("bet-bt").click();
                break;
            } else { 
                alert('something is wrong' );
                ///document.getElementById("bet-bt").click(); 
                break;
            }
        }
        start();
    };
};
7
  • you are declaring start() function twice? Commented Oct 21, 2014 at 6:23
  • Please make working fiddle of this and let us know Commented Oct 21, 2014 at 6:24
  • sorry i somehow pasted the same piece twice. it is correct now, still need advice on the click problem though Commented Oct 21, 2014 at 6:27
  • @Regent well it still might be called event handler. I just want to make clear that it is not attached multiple times. I also would highly suggest not to use onclick="" in production code. Commented Oct 21, 2014 at 6:33
  • 2
    how can you use break without any loop. Commented Oct 21, 2014 at 6:34

1 Answer 1

1

may be try something like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('#sound-toggle').click(function(){ 


    var startingBet = 5;
    startingBet = parseFloat(startingBet);

    });

     $('#bet-bt').click(function(){ 

         setTimeout(start,50);
       });
});

function start() {

    //show if it is getting chip amount
    //var rr = document.getElementById('bet-rb-2').innerHTML; //neerdsa classs s3elec5to9r
    //var rr = document.getElementById('bet-rb-2').innerHTML; 
    //



    //select the result of the spin
    var result = document.getElementById('result-text').innerHTML;
    alert(result.length);
    if (result.length == 5) { //lost


        alert('lost');

    } else if ( result.length == 4) {  //won
        alert('won');
        //document.getElementById("bet-bt").click();

    } else { 
        alert('something is wrong' );
        ///document.getElementById("bet-bt").click(); 

    }
}
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Thankyou! this is working, jsut had to edit a few lines for make it happen. This part of my script is working perfectly now. I should have known this, but ive been coding for near 12 hours straight and my brain is fried... thanks you again

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.