The javascript code below creates just a single bomb. How can we create many bombs at a random using the code below. function bDrop(){ var element = document.getElementsByClassName('bomb')[0];...



The javascript code below creates just a single bomb. How can we create many bombs at a random using the code below.





function bDrop(){



       var element = document.getElementsByClassName('bomb')[0];

       var positionLeft = Math.ceil(Math.random() * window.innerWidth) +1;


       var tBomb = setInterval(function(){

        element.style.left = positionLeft + 'px';

           var positionTop = element.offsetTop;

           element.style.top = positionTop + 1 + 'px';

           if(positionTop+ element.offsetHeight == window.innerHeight){

               clearInterval(tBomb);

               element.classList.add('explosion');

               element.classList.remove('bomb');




               setTimeout(function(){

                   element.classList.remove('explosion');

               }, 2000);


           }


       }, 10)

   }



Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here