mercredi 21 août 2019

Converting if-else into switch using javascript

I am new to javascript and want to convert an if-else block to a switch block.Any help would be really appreciated. I am new to switch syntax and so `i really need help in how to convert this if else block in to a switch block .Looking forward to all the help. :)

Best Regards

if (imagediv.contains(event.target)) {
return;      
 } 
 else if (event.target === newName && phoneDetails) {



newPoster.classList.toggle('active');

MyName.addEventListener('click',function(){

 imagediv.classList.remove('active');

});

  newImage.addEventListener('click',function(){
 imagediv.classList.add('active');
 });
  newPic.classList.toggle('active');

newIcon.addEventListener('click', function() {

newPic .classList.remove('active');
newPoster.classList.remove('active');
 });
 }
  else if(event.target===newImage && phoneDetails){

newPic.classList.toggle('active');
 imagediv.classList.toggle('active');

 newName.addEventListener('click',function(){

   imagediv.classList.remove('active');
      newPic.classList.remove('active');
  });
 } 


 else if (event.target === coldIcon && phoneDetails) {

newPoster.classList.toggle('active');
newIconIcon.classList.toggle('active');
}

 else if (event.target === newIcon && phoneDetails) {

  newPic.classList.add('active');
 newIconIcon.addEventListener('click', function() {

newPic.classList.remove('active');
newPoster.classList.remove('active');
});

 } 


 else if (phoneDetails) {
imagediv.classList.remove('active');
newPic.classList.remove('active');

}else{
oldImage.addEventListener('click', function(){
  newPic.classList.remove('active');
  }
});

Aucun commentaire:

Enregistrer un commentaire