 <p>You need to increment your <code>compteur</code> variable (I'm assuming that you have it for this purpose) and check it's value on every submission. Something like this:</p> <pre><code>var resultat = Math.floor(Math.random() * 100) + 1; var compteur = 1; $('div').html("( answer is : " + resultat + " )"); $('form').on('submit', function(e) { e.preventDefault(); if (compteur &lt; 8) { var inputVal = $('#number').val(); var nbInput = Number(inputVal); compteur++; if (nbInput !== resultat) { if (nbInput &lt; resultat) { $('h2').html(inputVal + ' is too small'); } else { $('h2').html(inputVal + ' is too big'); }; } else { $('h2').html('Yes! ' + inputVal + ' is the right number'); }; } else $('h2').html('You reached the limit of 7 guesses.'); }); </code></pre> <p>I've updated <a href="https://jsfiddle.net/9x0nLy43/24/" rel="nofollow">your fiddle so you can see it</a>.</p>