I was recently going through my son's workbook and it had an interest way of teaching addition - probably the Montessori method. The idea was to create a table of sum's of a few numbers and color numbers to see a pattern. I was quite amused and decided to see if I could write the code in JavaScript, a language I am trying to learn, I am going to do some additional work like graphical Towers of Hanoi with it as well, but for now I wanted to start simple
Guess what - I succeeded in writing what I consider as a useful program (although I wrote it quite badly)
Here is the code
Here is the Javascript
Here is the output
Guess what - I succeeded in writing what I consider as a useful program (although I wrote it quite badly)
Here is the code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<title> Summation for Children </title> | |
<style type="text/css"> | |
table.school { | |
font-family: verdana,arial,sans-serif; | |
font-size:11px; | |
color:#333333; | |
border-width: 1px; | |
border-color: #999999; | |
border-collapse: collapse; | |
} | |
table.school th { | |
background:#FAFAD2; | |
border-width: 1px; | |
padding: 8px; | |
border-style: solid; | |
border-color: #999999; | |
} | |
table.school td { | |
background:#FAFAD2; | |
border-width: 1px; | |
padding: 8px; | |
border-style: solid; | |
border-color: #999999; | |
} | |
</style> | |
<body> | |
</body> | |
<script src="buildsum.js"></script> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var n = 5; | |
var red="FF0000"; | |
var blue="87CEFA"; | |
var green="00FF00"; | |
var purple="A020F0"; | |
var orange="FFA500"; | |
var yellow="FFFF00"; | |
document.writeln("<table class=\"school\" id=\"sumtable\">"); | |
var tableid=document.getElementById("sumtable"); | |
var rows=tableid.getElementsByTagName("tr"); | |
var color = "red"; | |
var ids=1; | |
var el; | |
document.writeln("<tr>"); | |
document.write("<th>"); | |
document.write("+"); | |
document.write("</th>"); | |
for (i = 0; i <= n; i++) { | |
document.write("<th>"); | |
document.write(i); | |
document.write("</th>"); | |
} | |
document.writeln("</tr>"); | |
for (i = 1; i <= n+1; i++) { | |
document.writeln("<tr>"); | |
for (j = -1; i+j-1 <= n; j++) { | |
if (j == -1) { | |
document.write("<th>"); | |
document.write(i+j); | |
document.write("</th>"); | |
} else { | |
document.write("<td id=\"" + ids + "\">"); | |
el = document.getElementById(ids); | |
switch (i+j-1) { | |
case 0: | |
el.style.backgroundColor="#" + red.toString(16); | |
break; | |
case 1: | |
el.style.backgroundColor="#" + purple.toString(16); | |
break; | |
case 2: | |
el.style.backgroundColor="#" + blue.toString(16); | |
break; | |
case 3: | |
el.style.backgroundColor="#" + orange.toString(16); | |
break; | |
case 4: | |
el.style.backgroundColor="#" + yellow.toString(16); | |
break; | |
case 5: | |
el.style.backgroundColor="#" + green.toString(16); | |
break; | |
} | |
ids++; | |
document.write(i+j-1); | |
document.write("</td>"); | |
} | |
} | |
document.writeln("</tr>"); | |
} | |
document.writeln("</table>"); |