lundi 7 décembre 2020

Javascript Eventlistener unexpected else

Could someone tell me what's wrong with this eventListener? I keep getting unexpected token 'else' on it and don't get why.

JS:

hearts.forEach((span) => span.addEventListener("click", (event) => {
  
  if( heart.classList.contains("liked")){
    $('.photoLikes').each(function() {
      sum = sum + (.35);
    } ) ;
    likeInfo.textContent=  (parseFloat(sum).toFixed(0)) ;
  } ; 
                
  else{
    $('.photoLikes').each(function() {
      sum = sum - (.35);
    } ) ;
    likeInfo.textContent=  (parseFloat(sum).toFixed(0)) ;
  } ; 
}

CodePen with full code(it's the eventlistener in comment at the end of the JS):

https://codepen.io/enukeron/pen/qBaZNbb?editors=1111

Aucun commentaire:

Enregistrer un commentaire