Help calling a JavaScript function - Build a random phrase

Help calling a JavaScript function - Build a random phrase
0.0 0

#1

I am not sure why the code doesn’t execute my function. The code is in this codepen

I had it working and I changed something and now it doesn’t work. Thanks.


#2

You have an extra )

return quote[quotenum]);


#3

Cjsheets,
Thanks so much! How do I debug something like that? Any tips? Thanks.


#4

It’s no problem at all. There are many debugging techniques and they become easier to use the more you practice.

For one, certain IDEs will help flag extra brackets/parentheses. Codepen tries to flag them as well. When I visit your pen I see a red exclamation point at the bottom of the JS tab. When i click it I see this:

The editor is trying to identify the line with an error.

Second, you can check brackets by placing your mouse next to them. Codepen or IDEs will underline both matching brackets. Because the function contains an unmatched bracket Codepen can’t find the pair to underline and the bracket turns red.

Finally, instead of alerts you can use console.log( 'Variable Name: ’ + myJavascriptVariable ); to check how far your function executes before it fails. You can click the console tab at the bottom of Codepen to see the console.log output.

Those, I’d say, are the main debugging techniques I’d stick to for now.