Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Apparently 3 >= 2789

Aashishkebab

New Coder
I have this function:

JavaScript:
// Increments the scrubber's value based on the speed the user has set and calls seek(). If at max, pauses.
function tickClock(){
    if(document.getElementById('TheScrubber').value >= document.getElementById('TheScrubber').max){
        clearInterval(clock);
        document.getElementById('PlayPauseButton').src = 'play.png';
        alert(document.getElementById('TheScrubber').value);
        alert(document.getElementById('TheScrubber').max);
    }
    else{               
        document.getElementById('TheScrubber').value++;
        seek();
    }
}

When the left-hand side of the if is equal to 3 (and the right-hand side is always 2,789), this statement executes as true and I get the alerts that I have placed inside the if statement. WTF. And yes, I've ensured max and value are integers. Value gets incremented every second.
 
I have this function:

JavaScript:
// Increments the scrubber's value based on the speed the user has set and calls seek(). If at max, pauses.
function tickClock(){
    if(document.getElementById('TheScrubber').value >= document.getElementById('TheScrubber').max){
        clearInterval(clock);
        document.getElementById('PlayPauseButton').src = 'play.png';
        alert(document.getElementById('TheScrubber').value);
        alert(document.getElementById('TheScrubber').max);
    }
    else{              
        document.getElementById('TheScrubber').value++;
        seek();
    }
}

When the left-hand side of the if is equal to 3 (and the right-hand side is always 2,789), this statement executes as true and I get the alerts that I have placed inside the if statement. WTF. And yes, I've ensured max and value are integers. Value gets incremented every second.

Hi there,
Might want to actually convert your strings into Number(str) ;)
 
HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
    body, input{text-align: center;}
    </style>
  </head>
  <body>   
      <input id="TheScrubber" value="0" max="2789">
    <script>
   const scr = document.getElementById('TheScrubber'),
         clock = setInterval(tickClock, 5);
  
function tickClock(){
    if( +scr.value >= +scr.max){
        clearInterval(clock);
        alert(`value = ${scr.value}; max = ${scr.max}`);
    }
    else{               
        scr.value++;
    }
}
   </script>
  </body>
</html>
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom