Aquí está el desafío:
Cree una función makePlans que acepte una cadena. Esta cadena debe ser un nombre. La función makePlans debe llamar a la función callFriend y devolver el resultado. callFriend acepta un valor booleano y una cadena. Pase la variable y el nombre friendsAvailable a callFriend.
Cree una función llamada Amigo que acepte un valor booleano y una cadena. Si el valor booleano es verdadero, callFriend debería devolver la cadena 'Planes hechos con NOMBRE este fin de semana'. De lo contrario, debería devolver 'Todos están ocupados este fin de semana'.>
Esto es lo que escribí:
let friendsAvailable = true; function makePlans(name) { return callFriend(friendsAvailable, name); } function callFriend(bool, name) { if (bool = true) { return 'Plans made with ' + (name) + ' this weekend' } else { 'Everyone is busy this weekend' } } 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."Además de la parte if (bool = true) que todos ya han señalado (podría usar if (bool) para esto), olvidó agregar return en la declaración else . Debería ser:
} else { return 'Everyone is busy this weekend' }Código completo:
let friendsAvailable = true; function makePlans(name) { return callFriend(friendsAvailable, name); } function callFriend(bool, name) { if (bool) // or if (bool===true), but testing if true is true is a little bit redundant { return 'Plans made with ' + (name) + ' this weekend' } else { return 'Everyone is busy this weekend' } } 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."Pero si quieres impresionar a tu profesor haz esto:
const callFriend = (bool, name) => bool ? `Plans made with ${name} this weekend` : 'Everyone is busy this weekend' const makePlans = name => callFriend(friendsAvailable, name); let friendsAvailable = true console.log(makePlans('Mary')) friendsAvailable = false console.log(makePlans('James')) algunos ayudantes:
Expresiones de función de flecha
Operador condicional (ternario)