• Home
  • Business
  • Marketing
  • Lifehacks
  • Food & Fitness

TechLatte: Cheryl Marquez

Digital Marketing Can Be Hard, It Doesn't Need to Be

Avoid This Rookie Mistake in JavaScript

After taking 3 months off from learning JavaScript as part of the FreeCodeCamp front end development certification program, work finally slowed down to tackle some exercises during lunch. The topic was “Multiple Identical Options in Switch Statements”. While I successfully added a case statement for each number in the range, I made a simple rookie mistake.
I jumped right in by creating all of the cases and break statements, making sure to add the semicolons where appropriate. Before adding “switch(val) {“ to start the switch statement, added that then ran the tests.
The error I got was “SyntaxError: Unexpected end of input”. I googled the syntax for a switch statement and read through the documentation on StackOverflow. Then a lightbulb lit up in my head to check if the code had closing curly braces to match the starting curly braces. You’ll see in the screenshots, how I fixed the problem to successfully execute the switch statement.
Make sure your functions have matching closing curly braces.
some(code) {
return “Did you check for closing curly braces?”;
}
SyntaxError: Unexpected end of input
Solution: Check the code to make sure all curly braces have a matching closing curly brace.

Turns out I forgot to close the switch statement, you’ll see the missing curly brace below.

Successful execution of switch statement with the multiple versions of the same option.

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to email this to a friend (Opens in new window)
  • More
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to print (Opens in new window)

April 6, 2017 Cheryl Marquez Learning to Code Leave a Comment

« Lessons Learned From My First Facebook Live Stream
Managing Imposter Syndrome in a New Role »

Leave a Reply Cancel reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © 2023 TECHLATTE

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.