Menu

Question Relates Javascript Could Please Show Get Code Working Please Keep Simple Code Gre Q43807146

This question relates to JavaScript.

Could you please show me how to get my code below working.Please keep it simple.

The code has a green square image.  When it is clickedthe function generates a random number from 1-3. If the numbergenerated is ‘1’ then the green square is replaced by a picture ofa tree. Please keep it as simple as possible because I am new tocoding. Please answer it using the MINIMAL changes to mycode. Thanks.

<html>
<head>      
       <title></title>
      
<script>
       var randNum;
       var but;
       var but1;
      
       //var imageArray =[“greenSq1″,”greenSq2″,”greenSq3”];
      

       /**
       * This function generates a randomnumber between 1-3
       */
       function randFun1(){
           randNum =Math.floor(Math.random()*10);
           randNum =Math.round(randNum/3);
              if(randNum !=0){
                  rNum = randNum;
              }
                  if(rNum == 1){
                     document.getElementById(“greenSq1”).src = “tree”;
                     
                  }
       }
      
</script>
</head>

<body>
       <img id=”greenSq1″src=”greenSquare.png” onClick=”randFun1″style=”width:100px;height:100px;visibility:visible”/>
       <img id=”tree” src=”tree.jpg”style=”width:100px;height:100px;visibility:hidden”/>
      
</body>
  
</html>

Expert Answer


Answer to This question relates to JavaScript. Could you please show me how to get my code below working. Please keep it simple. T…

OR