首页 > 解决方案 > 创建一个接受字符串的函数并创建一个接受布尔值和字符串的函数

问题描述

创建一个接受字符串的函数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'

标签: stringfunctionif-statementboolean

解决方案


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."

推荐阅读