这是输入框部分(HTML)。函数的定义和我当前未填写的for循环。
<input type="number" id="num1"><!--Fill in the number-->
<input type="number" id="num2"><!--Fill in the power-->
<button onClick="multByItself()">Enter</button>
<script>
function multByItself(){
var num1 = document.getElementById("num1");
var num2 = document.getElementById("num2");
for(var i = 0; i < num2; i++){
// I am unsure what to fill in here
}
}
</script>
您可以简单地使用Math.pow函数来实现所需的功能,而无需使用任何循环。 for循环直接解决了您的问题。