Hi, i am working in to example active learning of function return values( https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Return_values) github repository(https://github.com/mdn/learning-area/blob/master/javascript/building-blocks/functions/function-library-finished.html), and i try to add a new function square Root but it does not work, please can you help me ?.
function squaredRoot(num = null) {
let contador = 0;
for (let i = 1; i<= num; i++){
contador++;
if((contador*contador) === num){
break;
}
}
return contador;
}
//this is the easy way and is perfectly functional in the console and event onchange.
function squaredRoot2(num = null) {
return Math.sqrt(num);
}
//in the console the function squareRoot is functional, but in the event onchange does not work, why?
input.onchange = function() {
let num = input.value;
if (isNaN(num)) {
para.textContent = 'You need to enter a number!';
} else {
para.textContent = num + ' squared is ' + squared(num) + '. ' +
num + ' cubed is ' + cubed(num) + '. ' +
num + ' square root is ' + squaredRoot(num) + '. ' +
num + ' factorial is ' + factorial(num) + '.';
}
}