我正在尝试学习如何在函数中输出函数。
Objective;函数 NameOutput(( 在运行时应该从 'randomMath((' 函数输出一个随机数。
我似乎只能输出字符串,如果我选择这样做,我该如何输出其他函数的结果?
在此之后,我将尝试使用"nameOutput"函数中的"randomMath"函数从我选择的数组中输出名称。
let names = ['1', '2', '3', '4', '5', '6']
// let random = Math.floor(Math.random() * 7);
let response;
function nameOutput() {
response = randomMath();
}
nameOutput()
let section = document.querySelector('body');
section.innerHTML = ' ';
let para1 = document.createElement('p');
para1.textContent = response;
section.appendChild(para1);
function randomMath() {
Math.floor(Math.random() * 7);
}
像这样从 randomMath 函数返回值。 需要返回值。
let names = ['1', '2', '3', '4', '5', '6']
// let random = Math.floor(Math.random() * 7);
let response;
function nameOutput() {
response = randomMath();
}
nameOutput()
let section = document.querySelector('body');
section.innerHTML = ' ';
let para1 = document.createElement('p');
para1.textContent = response;
section.appendChild(para1);
function randomMath() {
return Math.floor(Math.random() * 7);
}