Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var number = 1;
- document.write('<table>');
- for (var i = 0; i < 4; i++) {
- document.write('<tr>');
- for (var j = 0; j < 4; j++) {
- document.write('<td id="'+number+'"></td>');
- number++;
- }
- document.write('<td class="button" onclick="switchLightRow('+(number-1)+')"></td>');
- document.write('</tr>');
- }
- document.write('<tr>');
- for (var k = 0; k < 4; k++) {
- document.write('<td class="button" onclick="switchLightColumn('+(k+1)+')"></td>');
- }
- document.write('</tr>');
- document.write('</table>');
- function switchLightRow(num) {
- for (var i = 0; i < 4; i++) {
- numcase = num - i;
- if (document.getElementById(numcase).style.backgroundColor == 'white') {
- document.getElementById(numcase).style.backgroundColor = "yellow";
- }else {
- document.getElementById(numcase).style.backgroundColor = "white";
- }
- }
- td = document.getElementsByTagName('td');
- var lightIsOn = 0;
- for (var i = 0; i < td.length; i++) {
- if(td[i].style.backgroundColor == "yellow"){
- lightIsOn++;
- }
- }
- console.log(lightIsOn);
- if (lightIsOn == 16) {
- document.write('Félicitations !')
- }
- var lightIsOn = 0;
- }
- function switchLightColumn(num){
- for (var i = 0; i < 4; i++) {
- numcase = num + i * 4;
- if (document.getElementById(numcase).style.backgroundColor == 'white') {
- document.getElementById(numcase).style.backgroundColor = "yellow";
- }else {
- document.getElementById(numcase).style.backgroundColor = "white";
- }
- }
- td = document.getElementsByTagName('td');
- var lightIsOn = 0;
- for (var i = 0; i < td.length; i++) {
- if(td[i].style.backgroundColor == "yellow"){
- lightIsOn++;
- }
- }
- console.log(lightIsOn);
- if (lightIsOn == 16) {
- document.write('Félicitations !')
- }
- var lightIsOn = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement