function hey(str) {
for (let char of str){
if (str.slice(-1) !== "?" && str === str.toUpperCase() && str !== " "){
return 'Whoa, chill out!';
}
else if (str.slice(-1) === "?" && str === str.toUpperCase()){
return "Calm down, I know what I'm doing!";
}
else if(str.slice(-1) === "?" && str !== str.toUpperCase()){
return "Sure.";
}
else if (str === " " || str === undefined){
return "Fine. Be that way!";
}
else {
return 'Whatever.';
}
}
}
hey('');
Bob Bob is a lackadaisical teenager. In conversation, his responses are very limited.
Bob answers 'Sure.' if you ask him a question.
He answers 'Whoa, chill out!' if you yell at him.
He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
He says 'Fine. Be that way!' if you address him without actually saying anything.
He answers 'Whatever.' to anything else.
Aucun commentaire:
Enregistrer un commentaire