Advertisement
Guest User

Untitled

a guest
May 16th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var number = 1;
  2.     document.write('<table>');
  3.     for (var i = 0; i < 4; i++) {
  4.       document.write('<tr>');
  5.       for (var j = 0; j < 4; j++) {
  6.         document.write('<td id="'+number+'"></td>');
  7.         number++;
  8.       }
  9.       document.write('<td class="button" onclick="switchLightRow('+(number-1)+')"></td>');
  10.       document.write('</tr>');
  11.     }
  12.     document.write('<tr>');
  13.     for (var k = 0; k < 4; k++) {
  14.       document.write('<td class="button" onclick="switchLightColumn('+(k+1)+')"></td>');
  15.     }
  16.     document.write('</tr>');
  17.     document.write('</table>');
  18.  
  19.  
  20.     function switchLightRow(num) {
  21.       for (var i = 0; i < 4; i++) {
  22.           numcase = num - i;
  23.           if (document.getElementById(numcase).style.backgroundColor == 'white') {
  24.  
  25.             document.getElementById(numcase).style.backgroundColor = "yellow";
  26.  
  27.           }else {
  28.             document.getElementById(numcase).style.backgroundColor = "white";
  29.           }
  30.       }
  31.       td = document.getElementsByTagName('td');
  32.       var lightIsOn = 0;
  33.       for (var i = 0; i < td.length; i++) {
  34.         if(td[i].style.backgroundColor == "yellow"){
  35.           lightIsOn++;
  36.         }
  37.       }
  38.       console.log(lightIsOn);
  39.       if (lightIsOn == 16) {
  40.         document.write('Félicitations !')
  41.       }
  42.       var lightIsOn = 0;
  43.  
  44.     }
  45.  
  46.     function switchLightColumn(num){
  47.       for (var i = 0; i < 4; i++) {
  48.         numcase = num + i * 4;
  49.         if (document.getElementById(numcase).style.backgroundColor == 'white') {
  50.  
  51.           document.getElementById(numcase).style.backgroundColor = "yellow";
  52.  
  53.         }else {
  54.           document.getElementById(numcase).style.backgroundColor = "white";
  55.         }
  56.       }
  57.       td = document.getElementsByTagName('td');
  58.       var lightIsOn = 0;
  59.       for (var i = 0; i < td.length; i++) {
  60.         if(td[i].style.backgroundColor == "yellow"){
  61.           lightIsOn++;
  62.         }
  63.       }
  64.       console.log(lightIsOn);
  65.       if (lightIsOn == 16) {
  66.         document.write('Félicitations !')
  67.       }
  68.       var lightIsOn = 0;
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement