string - 创建一个接受字符串的函数并创建一个接受布尔值和字符串的函数
问题描述
创建一个接受字符串的函数makePlans。这个字符串应该是一个名字。函数makePlans应该调用函数callFriend并返回结果。callFriend接受一个布尔值和一个字符串。将friendsAvailable变量和名称传递给callFriend。
创建一个接受布尔值和字符串的函数callFriend 。如果布尔值为 true,则 callFriend应返回字符串'Plans made with NAME this week'。否则它应该返回“这个周末每个人都很忙”。
到目前为止,这就是我想出的:让friendsAvailable = true;
function makePlans(name) {
// INSERT CODE HERE
return `Plans made with ${name} this weekend`;
}
function callFriend(bool, name) {
// INSERT CODE HERE
if (callFriend = true); {
return 'Plans made with ${name} this weekend';
} else (callFriend = false) {
return "Everyone is busy this weekend";
}
}
// Uncomment these to check your work!
console.log(makePlans("Mary")) // should return: "Plans made with Mary this weekend'
friendsAvailable = false;
console.log(makePlans("James")) //should return: "Everyone is busy this weekend."
我无法弄清楚要纠正什么,控制台告诉我有一个语法错误:意外令牌'else'
解决方案
So I managed to put
let friendsAvailable = true;
function makePlans(name) {
// INSERT CODE HERE
return callFriend(friendsAvailable, name);
}
function callFriend(bool, name) {
// INSERT CODE HERE
if (bool) {
return (`Plans made with ${name} this weekend`);
} else {
return "Everyone is busy this weekend";
}
}
// Uncomment these to check your work!
console.log(makePlans("Mary")) // should return: "Plans made with Mary this
weekend'
friendsAvailable = false;
console.log(makePlans("James")) //should return: "Everyone is busy this weekend."
推荐阅读
- postgresql - 在 PostgreSQL 过程中的 CTE 之后运行 FOREACH?
- c# - 如何使用 iText7 防止 Pdf 文件中的交互字段变平
- png - Deepstream 姿态估计无法检测到任何骨架
- android - 实时数据中的 Observables 更新在片段中不起作用
- azure - 天蓝色数据工厂中基于事件的触发器
- powershell - 在 Windows Server 2012 R2 上运行 Shell 脚本并在另一个 VM 上获取 Toast 通知
- c - 这个没有 libc 的 C 程序如何工作?
- bootstrap-vue - 如何为 bootstrap-vue 动态设置 scss 变量 $body-bg 和 $body-color?
- javascript - 需要使用 Highchart.js 库的金字塔图
- javascript - 如何在javascript中修复此功能冷却?