mardi 28 février 2017

How to show a message on a certain number count using parseInt (javascript)?

Hello :) Using parseInt I made a function that counts how many times you've clicked a certain button. Now I want to adjust this function or create another function that will show a message at a certain amount of clicks. This is how I count the clicks:

var cnt=0;
function CountBats(){
 cnt=parseInt(cnt)+parseInt(1);
 var divData=document.getElementById("showBats");
 divData.innerHTML="Total number of bats: "+cnt +"";
};

This is what I thought would show a message, but it doesn't work:

var cn=0;
function Nice(){
    cn=parseInt(cn)+parseInt(1);
    var divNice=document.getElementById("Nice");
    if (cn = 1) { 
    divNice.style.animation="nice 2s ease-out alternate 2";
    divNice.innerHTML="Nice!";}};

It did work when I put the if statement inside the counting function, but the problem with that was that the counter stopped after the button had been clicked twice. Question is, how do I make this work? (NB: I would like to do this in javascript, not jquery) Thanks in advance :)

Aucun commentaire:

Enregistrer un commentaire