-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More worksheets & optional answer key
- Loading branch information
Lewis Nakao
committed
Jul 20, 2020
1 parent
0fa6459
commit 91ffd7c
Showing
10 changed files
with
300 additions
and
203 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | ||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | ||
ga('create', 'UA-2833478-13', 'auto'); | ||
ga('send', 'pageview'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
const rand = max => Math.floor(Math.random() * max); | ||
const randRange = (min, max) => rand(max - min) + min; | ||
const randArr = arr => arr[rand(arr.length)]; | ||
const singleDigits = [2,3,4,5,6,7,8,9]; | ||
const randNoOnes = () => randArr(singleDigits); | ||
const randRangeByDigits = (digits, noOnes = false) => { | ||
if (noOnes && digits === 1) return randNoOnes(); | ||
const start = Math.pow(10, digits - 1); | ||
const end = Math.pow(10, digits) - 1; | ||
console.log({start, end}) | ||
return randRange(start, end); | ||
}; | ||
const solution = (x, y, mathSymbol) => { | ||
switch (mathSymbol) { | ||
case "*": return x * y; | ||
case "/": return x / y; | ||
case "-": return x - y; | ||
default: return x + y; | ||
} | ||
}; | ||
const getUrlParam = param => { | ||
const paramMap = {}; | ||
const urlArr = document.location.href.split("?"); | ||
const queryParam = urlArr.length > 1 ? urlArr[1] : false; | ||
if (queryParam) { | ||
var paramArr = queryParam.split("&"); | ||
paramArr.map(paramSet => { | ||
if (paramSet.indexOf(param + "=") === 0) { | ||
paramMap[param] = paramSet.split("=")[1].replace(/%20/g, " "); | ||
} | ||
}); | ||
} | ||
return paramMap[param] || false; | ||
}; | ||
const genEquation = (xSize, ySize, mathSymbol, noOnes = false) => { | ||
const x = randRangeByDigits(xSize, noOnes); | ||
const y = randRangeByDigits(ySize, noOnes); | ||
const z = solution(x, y, mathSymbol); | ||
return { x, y, z }; | ||
}; | ||
const generate = (xSize, ySize, mathSymbol, count) => { | ||
const arr = []; | ||
if (xSize === 1 && ySize === 1) { | ||
singleDigits.map(x => singleDigits.map(y => arr.push({ x, y, z: solution(x, y, mathSymbol) }))); | ||
arr.sort(() => Math.random() - 0.5); //shuffle | ||
arr.sort(() => Math.random() - 0.5); //shuffle | ||
} | ||
else { | ||
for (let i = 0; i < count; i++) { | ||
arr.push(genEquation(xSize, ySize, mathSymbol)); | ||
} | ||
} | ||
return arr; | ||
}; | ||
window.onload = () => { | ||
const setName = getUrlParam("set") || "addition" | ||
//, copies = getUrlParam("copies") || 1 | ||
, showAnswerKey = getUrlParam("showAnswerKey") || false | ||
, output = document.getElementById("output") | ||
, answerKey = document.getElementById("answerKey") | ||
, titleDiv = document.getElementById("title") | ||
, hwSet = hwSets[setName] | ||
, { title, count, columns, xSize, ySize, mathSymbol, outputFunc, noOnes } = hwSet | ||
, arr = generate(xSize, ySize, mathSymbol, count, noOnes) | ||
, outputStr = arr.map((eq, i) => outputFunc(eq, i, columns)).join("") | ||
, answersStr = showAnswerKey ? '<div class="answer-key-table">' + arr.map(hwSet.answerKey).map((a, i) => | ||
`<span class="answer-key">${i + 1}.) ${a}</span>`).join("") + '</div>' : '' | ||
; | ||
document.title = title; | ||
titleDiv.innerHTML = title; | ||
output.innerHTML = '<tr>' + outputStr + '</tr>'; | ||
answerKey.innerHTML = answersStr; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
const hwSets = { | ||
"addition": { | ||
title: "Addition 1-digit Equations", | ||
count: 20, | ||
columns: 3, | ||
xSize: 1, | ||
ySize: 1, | ||
mathSymbol: "+", | ||
outputFunc: (eq, i, columns) => ` | ||
<td class="inline-equation text-nowrap"> | ||
<span class="number">${i + 1}.)</span>${eq.x} + ${eq.y} = | ||
</td> | ||
<td class="answer"><input type="text" class="answer-input-d"/></td> | ||
${((i + 1) % columns) === 0 ? '</tr><tr>' : ''}`, | ||
answerKey: eq => eq.z, | ||
}, | ||
"addition-find-addends": { | ||
title: "Addition Find Addends 1-digit Equations", | ||
count: 20, | ||
columns: 3, | ||
xSize: 1, ySize: 1, mathSymbol: "+", | ||
outputFunc: (eq, i, columns) => ` | ||
<td class="inline-equation text-nowrap"> | ||
<span class="text-muted mr-2 number">${i + 1}.)</span> | ||
${eq.x} + <input type="text" class="answer-input-d"/> = | ||
</td> | ||
<td class="answer">${eq.z}</td> | ||
${((i + 1) % columns) === 0 ? '</tr><tr>' : ''}`, | ||
answerKey: eq => eq.y, | ||
}, | ||
"addition-2-1": { | ||
title: "Addition 2-1-digit Equations", | ||
count: 40, columns: 4, | ||
xSize: 2, ySize: 1, noOnes: true, mathSymbol: "+", | ||
outputFunc: (eq, i, columns) => ` | ||
<td><span class="number">${i + 1}.)</span></td> | ||
<td class="pb-5"> | ||
<div class="equation">${eq.x}</div> | ||
<div class="equation">+ ${eq.y}</div> | ||
<div class=" equation"><input type="text" class="answer-input"/></div> | ||
</td> | ||
${((i + 1) % columns) === 0 ? '</tr><tr>' : ''}`, | ||
answerKey: eq => eq.z, | ||
}, | ||
"addition-2-2": { | ||
title: "Addition 2-2-digit Equations", | ||
count: 40, columns: 4, | ||
xSize: 2, ySize: 2, noOnes: true, mathSymbol: "+", | ||
outputFunc: (eq, i, columns) => ` | ||
<td><span class="number">${i + 1}.)</span></td> | ||
<td class="pb-5"> | ||
<div class="equation">${eq.x}</div> | ||
<div class="equation">+ ${eq.y}</div> | ||
<div class=" equation"><input type="text" class="answer-input"/></div> | ||
</td> | ||
${((i + 1) % columns) === 0 ? '</tr><tr>' : ''}`, | ||
answerKey: eq => eq.z, | ||
}, | ||
"multiplication": { | ||
title: "Multiplication 1-digit Equations", | ||
count: 64, | ||
columns: 3, | ||
xSize: 1, | ||
ySize: 1, | ||
mathSymbol: "*", | ||
outputFunc: (eq, i, columns) => ` | ||
<td class="inline-equation text-nowrap"> | ||
<span class="number">${i + 1}.)</span> ${eq.x} × ${eq.y} = | ||
</td> | ||
<td class="answer"> | ||
<input type="text" class="answer-input-d"/> | ||
</td> | ||
${((i + 1) % columns) === 0 ? '</tr><tr>' : ''}`, | ||
answerKey: eq => eq.z, | ||
}, | ||
"multiplication-find-multiple": { | ||
title: "Multiplication Find Multiple 1-1-digit Equations", | ||
count: 20, | ||
columns: 3, | ||
xSize: 1, | ||
ySize: 1, | ||
mathSymbol: "*", | ||
outputFunc: (eq, i, columns) => ` | ||
<td class="inline-equation text-nowrap"> | ||
<span class="number">${i + 1}.)</span> ${eq.x} × | ||
<input type="text" class="answer-input-d"/> = | ||
</td> | ||
<td class="answer"> | ||
${eq.z} | ||
</td> | ||
${((i + 1) % columns) === 0 ? '</tr><tr>' : ''}`, | ||
answerKey: eq => eq.y, | ||
}, | ||
"multiplication-2-1": { | ||
title: "Muliplication 2 to 1-digit Equations", | ||
count: 40, | ||
columns: 4, | ||
xSize: 2, | ||
ySize: 1, | ||
mathSymbol: "*", | ||
noOnes: true, | ||
outputFunc: (eq, i, columns) => ` | ||
<td><span class="number">${i + 1}.)</span></td> | ||
<td class="pb-5"> | ||
<div class="equation">${eq.x}</div> | ||
<div class="equation">× ${eq.y}</div> | ||
<div class=" equation"><input type="text" class="answer-input"/></div> | ||
</td> | ||
${((i + 1) % columns) === 0 ? '</tr><tr>' : ''}`, | ||
answerKey: eq => eq.y, | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
let answerKeyCbx = document.getElementById("answerKeyCbx"); | ||
let answerKey = answerKeyCbx.checked; | ||
const toggleAnswerKey = elem => { | ||
answerKey = elem.checked; | ||
render(); | ||
}; | ||
window.onload = () => render(); | ||
const render = () => { | ||
const output = document.getElementById("output"); | ||
output.innerHTML = Object.keys(hwSets).map((a, i) => { | ||
const {title, xSize, ySize, mathSymbol, outputFunc, count} = hwSets[a]; | ||
const eq = genEquation(xSize, ySize, mathSymbol); | ||
const eqStr = outputFunc(eq, -1, 0); | ||
return `<tr> | ||
<td class="text-right pr-0 text-sm"> | ||
<span class="mr-2 number">${i + 1}.</span> | ||
</td> | ||
<td> | ||
<a href="worksheet.html?set=${a}${answerKey ? '&showAnswerKey=1' : ''}" target="_blank">${title}</a> | ||
${answerKey ? '<div class="text-muted">w/answer key</div>' : ''} | ||
${xSize === 1 && ySize === 1 ? 64 : count} Problems | ||
</td> | ||
<td>e.g.</td> | ||
<td style="width:10rem;"> | ||
<table class="w-50"><tbody><tr class="example">${eqStr}</tr></tbody></table> | ||
</td> | ||
</tr>`}).join(""); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.