我试图在一个函数中拆分和反转用户输入,即(Cat Food = Fot Caod)但是,它不是返回实际的函数数据,而是返回一个长函数字符串。我做错了什么?
谢谢!
var mixUp = prompt("Enter a word")
var mixUp2 = prompt("Enter a second word")
function myFunction(mixUp, mixUp2) {
var mixUp = mixUp.substring(0,2)
var mixUp2 = mixUp2.substring(0,2)
var myFunction = mixUp.concat(mixUp2);
return myFunction
}
document.write(myFunction)
答案 0 :(得分:3)
prompt
个功能。
function myFunction() {
var mixUp = prompt("Enter a word");
var mixUp2 = prompt("Enter a second word");
var mixUp = mixUp.substring(0, 2);
var mixUp2 = mixUp2.substring(0, 2);
return mixUp.concat(mixUp2);
}
document.write(myFunction())

答案 1 :(得分:-1)
我不确定该功能的逻辑,但
你做错了是你正在为文件写一个函数对象
你只需要调用它并提供mixUp和mixUp2参数
var mixUp = prompt("Enter a word")
var mixUp2 = prompt("Enter a second word")
function myFunction(mixUp, mixUp2) {
var mixUp = mixUp.substring(0,2)
var mixUp2 = mixUp2.substring(0,2)
return mixUp.concat(mixUp2);
}
document.write(myFunction(mixUp , mixUp2))