I'm just starting programming, I have this issue and I can't finish it. where to use startsWith inside the function?
function werewolfCheck(name) {
if (name === str.startsWith('were')) {
return 'It is a werewolf';
} else {
return 'Just a regular person';
}
}
var werewolfCheck = name.str.startsWith('were');
werewolfCheck('werebrian');
function werewolfCheck (name) {
if (name.slice(0,4) === "were"){
return "it is a werewolf"
} else {
return "just a regular person"
}
};
console.log(werewolfCheck("werebrian"))
in the function str doesn't exist so you just need to check to see if name (the argument you passed in) starts with 'were'.
var werewolfCheck... does nothing useful so you can remove it.
The return from the function is a string so you need some way to display that string. I've logged it to the console in this example.
function werewolfCheck(name) {
if (name.startsWith('were')) {
return 'It is a werewolf';
} else {
return 'Just a regular person';
}
}
console.log(werewolfCheck('werebrian'));
console.log(werewolfCheck('Billy Joel'));
function werewolfCheck(name){
if(name.startsWith("were"))
return "It is werewolf";
return "Just a regular person";
}
werewolfCheck("werebrain");