Last active
March 23, 2018 21:37
-
-
Save viklund/45aa0b78dc8c4e05aecdfab04154f089 to your computer and use it in GitHub Desktop.
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> | |
<head> | |
<style> | |
div.q, div.a { | |
float: left; | |
width: 4.0em; | |
font-size: 14pt; | |
margin-bottom: 1em; | |
} | |
div.q { | |
padding-left: 1em; | |
} | |
div.a { | |
border-bottom: 1px solid black; | |
} | |
h1 { | |
width: 100%; | |
clear: both; | |
} | |
@media print { | |
.no-print { display: none; } | |
} | |
</style> | |
</head> | |
<body> | |
<p class="no-print"> | |
Det här är en förhandsgranskning. Det går att generera ett nytt problem | |
blad genom att ladda om sidan</p> | |
<div id="problems"></div> | |
<script> | |
var p = document.getElementById('problems'); | |
function n (n) { | |
return Math.ceil( Math.random() * n ) | |
} | |
function addition(e) { | |
var a = document.createElement('div'); | |
a.setAttribute('class', 'q'); | |
a.innerHTML = n(20) + ' + ' + n(10) + ' = '; | |
e.appendChild(a); | |
var a = document.createElement('div'); | |
a.setAttribute('class', 'a'); | |
a.innerHTML = ' '; | |
e.appendChild(a); | |
} | |
function simple_subtraction(e) { | |
var a = document.createElement('div'); | |
a.setAttribute('class', 'q'); | |
var n1 = n(10); | |
var n2 = n(10); | |
while (n1 < n2) { | |
n1 = n(10); | |
n2 = n(10); | |
} | |
a.innerHTML = n1 + ' - ' + n2 + ' = '; | |
e.appendChild(a); | |
var a = document.createElement('div'); | |
a.setAttribute('class', 'a'); | |
a.innerHTML = ' '; | |
e.appendChild(a); | |
} | |
function mellan_subtraction(e) { | |
var a = document.createElement('div'); | |
a.setAttribute('class', 'q'); | |
var n1 = n(20); | |
var n2 = n(10); | |
while (n1 < n2) { | |
n1 = n(10); | |
n2 = n(10); | |
} | |
a.innerHTML = n1 + ' - ' + n2 + ' = '; | |
e.appendChild(a); | |
var a = document.createElement('div'); | |
a.setAttribute('class', 'a'); | |
a.innerHTML = ' '; | |
e.appendChild(a); | |
} | |
function level3_subtraction(e) { | |
var a = document.createElement('div'); | |
a.setAttribute('class', 'q'); | |
var n1 = n(10)+17; | |
var n2 = n(10); | |
while (n1 < n2) { | |
n1 = n(10)+17; | |
n2 = n(10); | |
} | |
a.innerHTML = n1 + ' - ' + n2 + ' = '; | |
e.appendChild(a); | |
var a = document.createElement('div'); | |
a.setAttribute('class', 'a'); | |
a.innerHTML = ' '; | |
e.appendChild(a); | |
} | |
function rubbe(e, text) { | |
var h = document.createElement('h1'); | |
h.innerHTML = text; | |
e.appendChild( document.createElement('br') ); | |
e.appendChild( h ); | |
} | |
rubbe(p, 'Addition'); | |
for (i=0; i<16; i++) { | |
addition(p); | |
} | |
rubbe(p, 'Enkel Subtraktion'); | |
for (i=0; i<16; i++) { | |
simple_subtraction(p); | |
} | |
rubbe(p, 'Mellan Subtraktion'); | |
for (i=0; i<16; i++) { | |
mellan_subtraction(p); | |
} | |
rubbe(p, 'Svår Subtraktion'); | |
for (i=0; i<16; i++) { | |
level3_subtraction(p); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a very simple math sheet generator for my son.