创建一个接受字符串的函数 & 创建一个接受布尔值和字符串的函数

Creating a function that accepts a string & creating a function that accepts a boolean value and a string

创建一个接受字符串的函数 makePlans。这个字符串应该是一个名字。函数 makePlans 应该调用函数 callFriend 和 return 结果。 callFriend 接受一个布尔值和一个字符串。将 friendsAvailable 变量和名称传递给 callFriend.

创建一个接受布尔值和字符串的函数 callFriend。如果布尔值为 true,callFriend 应该 return 字符串 'Plans made with NAME this weekend'。否则应该 return 'Everyone is busy this weekend'.

到目前为止,这是我想出的: 让 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'

您在 if (callFriend = true); 行中多了一个 ;

; 有效地终止了 if 条件。它后面的大括号仅被视为封装块,这意味着当编译器到达 else 时它会感到困惑,因为它认为前面的 if 语句已完成。

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

**`

let friendsAvailable = true;

function makePlans(name) {
  // INSERT CODE HERE
  return callFriend(friendsAvailable, name);
}

function callFriend(bool, name) {
  // INSERT CODE HERE
  if (bool == true){
    return `Plans made with ${name} this weekend`
  } else if (bool == 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."

`**