claimReservation
功能。它应该:
使用' Bob'和特德'测试你的代码。
我的代码 :
var reservations = {
'Bob': { claimed: false },
'Ted': { claimed: true }
}
var name = prompt('Please enter the name for your reservation');
var claimReservation = function (name) {
if(reservations.claimed == "false"){
alert("Welcome")
}
else if(reservations.name.claimed == "true"){
alert("You have a problem bruh!")
}
else{
alert("No reservation by that name bruh")
}
}
claimReservation("Leeann");
claimReservation("Bob");
claimReservation("Ted")
`
答案 0 :(得分:0)
看起来你正在尝试使用提示获取名称,然后将“name”作为传入的变量引用到函数中?如果您有任何疑问,请参阅更新的代码并告诉我。
var reservations_ = {
'Bob': {
'claimed': false
},
'Ted': {
'claimed': true
}
};
var claimReservation = function(name) {
if (reservations_.hasOwnProperty(name) === false) {
alert("No reservation by that name bruh");
return;
}
if (reservations_[name].claimed === false) {
alert("Welcome " + name);
} else if (reservations_[name].claimed === true) {
alert(name + ", you have a problem bruh!");
}
};
claimReservation("Leeann");
claimReservation("Bob");
claimReservation("Ted");
var name = prompt('Please enter the name for your reservation');
claimReservation(name);