这是我的代码和JSFiddle。
我无法使代码工作,我认为这是因为内部包含for loop
的if语句。
如何使整个代码工作,我尝试了4种不同的代码可能性,但没有一种工作/
var commands = {
'BOH': {
text: 'BOH!',
},
'HALO': {
text: 'HALO!',
},
'help()': {
text: 'Please press F12 and see the value list.',
},
};
$(".code").on("click", function () {
var codePrompt = prompt("enter the value"),
command = commands[codePrompt],
alertMessage = "";
consoleMessage = "Used '" + codePrompt + "' value.";
if(!command) {
alertMessage = "We are sorry but you entered a WRONG value.";
} else {
alertMessage = command.text;
};
if(command == 'help()') {
for (key in commands){
console.log(commands[key]);
alertMessage = command.text;
};
};
alert(alertMessage);
console.log(consoleMessage);
});
答案 0 :(得分:0)
不应该
if(command == 'help()') {
是
if(codePrompt == 'help()') {