I need to create a calculator where the user inputs a number, and it calculates the factors, cube and square of the given number.
Below is the code i am using.. I have NO idea how to work out the factor. Any advice would be appreciated.
document.getElementById('calculate').addEventListener('click', estimateTotal);
function estimateTotal(event) {
event.preventDefault();
var initial2 = document.getElementById('initial').value;
document.getElementById('factor').value = 0;
document.getElementById('sqaure').value = initial2 * initial2;
document.getElementById('cube').value = initial2 * initial2 * initial2;
}
<form id="calculator" method="POST">
<p>Please enter a number between 0 and 50 <input name="initial" id="initial" type="text" size="20" required><button id="calculate">Calculate</button></p>
<p>The Factorial of your number is: <input name="factor" id="factor" class="factor" type="text" size="20"></p>
<p>The Square of your number is:<input name="sqaure" id="sqaure" class="sqaure" type="text" size="20"></p>
<p>The Cube of your number is:<input name="cube" id="cube" class="cube" type="text" size="20"></p>
</form>