Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
49
Task/Factorial/JavaScript/factorial-8.js
Normal file
49
Task/Factorial/JavaScript/factorial-8.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<html>
|
||||
|
||||
<body>
|
||||
|
||||
<button onclick="incrementFact()">Factorial</button>
|
||||
<p id="FactArray"></p>
|
||||
<p id="Factorial"></p>
|
||||
<br>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<input id="userInput" value="">
|
||||
<br>
|
||||
<button onclick="singleFact()">Single Value Factorial</button>
|
||||
<p id="SingleFactArray"></p>
|
||||
<p id="SingleFactorial"></p>
|
||||
|
||||
|
||||
<script>
|
||||
function mathFact(total, sum) {
|
||||
return total * sum;
|
||||
}
|
||||
|
||||
var incNumbers = [1];
|
||||
|
||||
function incrementFact() {
|
||||
var n = incNumbers.pop();
|
||||
incNumbers.push(n);
|
||||
incNumbers.push(n + 1);
|
||||
document.getElementById("FactArray").innerHTML = incNumbers;
|
||||
document.getElementById("Factorial").innerHTML = incNumbers.reduceRight(mathFact);
|
||||
|
||||
}
|
||||
|
||||
var singleNum = [];
|
||||
|
||||
function singleFact() {
|
||||
var x = document.getElementById("userInput").value;
|
||||
for (i = 0; i < x; i++) {
|
||||
singleNum.push(i + 1);
|
||||
document.getElementById("SingleFactArray").innerHTML = singleNum;
|
||||
}
|
||||
document.getElementById("SingleFactorial").innerHTML = singleNum.reduceRight(mathFact);
|
||||
singleNum = [];
|
||||
}
|
||||
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue