I’m almost done with my project. I did it slightly different then the what was asked but nevertheless I have it written up but I have a syntax error that doesn’t seem to make sense to me. This is the git link: https://github.com/berrysm91/Mixed-Messages.git
here is the relevant code:
var movieSelect = math.Floor(math.Random() * array.lengh);
const movieReturn = switch(moviePick) {
case 'Top Gun':
return topChar
break;
case 'Anchorman':
return anchorChar
break;
case 'Caddyshack':
return caddyChar
break;
case 'Fast Times at Ridgemont High':
return fastChar
break;
};
it shows the syntax error at switch but I can’t understand why
you can’t store statements in variables so just remove const movieReturn= from the above line.
if you want to store the return value of your function. do that after the function block:
const movieReturn = getQuote()
=============
Note: the break statements are unnecessary here, They will never be reached because return will stop the function, so you can remove them.
case 'Top Gun':
return topChar //end the function and return topChar
break; //unreachable code so just remove it
I think I have most of the code nailed down but when I run it I get [Function: getQuote] as the output. the most up to date code is in code3.js in the git repo in the first post
If you want to get the return value of a function you will have to call it first. console.log( getQuote() ) not console.log( getQuote ) and charReturn() not charReturn.
Also, I didn’t understand the reason for charSelect function, what are you trying to do with it and why did you nest getQuote function inside it?