Last active
October 12, 2016 15:22
-
-
Save camerican/b7b845e6017ceb61b3f57966ca610ecf to your computer and use it in GitHub Desktop.
Example of a simple function calculator w/ output to HTML Table
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
let elM, elC, elP, elR, points; | |
let min = -10 | |
let max = 10; | |
document.addEventListener("DOMContentLoaded",function(){ | |
elM = document.getElementById("m"); | |
elC = document.getElementById("c"); | |
elP = document.getElementById("p"); | |
elR = document.getElementById("result"); | |
document.getElementById("run").addEventListener("click",calculate); | |
}); | |
function functionResolver(m, c, p) { | |
let points = []; | |
for(let x=min; x<=max; x++) { | |
points.push( [x,m * ( x * x ) + c * x + p] ) | |
} | |
return points; | |
} | |
function calculate() { | |
points = functionResolver(+elM.value,+elC.value,+elP.value); | |
//wipe result table, creating col headings | |
elR.innerHTML = "<tr><th>x</th><th>y</th></tr>"; | |
points.forEach( coord => { | |
elR.innerHTML += `<tr><td>${coord[0]}</td><td>${coord[1]}</td></tr>\n`; | |
}); | |
} |
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
<input id="m" /> | |
<input id="c" /> | |
<input id="p" /> | |
<button id="run"> | |
Run Function | |
</button> | |
<table id="result"> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment