# Js help, Uncaught SyntaxError: Unexpected token '{'

**URL:** <https://forum.freecodecamp.org/t/js-help-uncaught-syntaxerror-unexpected-token/424369>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [October 6, 2020, 4:28pm UTC](https://forum.freecodecamp.org/t/js-help-uncaught-syntaxerror-unexpected-token/424369 "2020-10-06T16:28:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.manuel.6.mm](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/m.manuel.6.mm/32/182792_2.png) [@m.manuel.6.mm](https://forum.freecodecamp.org/u/m.manuel.6.mm)\
**Post date:** [October 6, 2020, 4:28pm UTC](https://forum.freecodecamp.org/t/js-help-uncaught-syntaxerror-unexpected-token/424369/1 "2020-10-06T16:28:06Z")

</div>

Hi everyone, I’m learning to use javascript and I ran into this problem.  
Can someone help me? I am pretty sure the syntax is correct but I keep getting this error: `Uncaught SyntaxError: Unexpected token '{'`.  
p.s I apologize in advance for my not so great english 😅

 ![error](https://global.discourse-cdn.com/freecodecamp/original/3X/9/e/9e1077a7de02bd211d51d4d02237af5b56ade3f3.png)

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [October 6, 2020, 4:35pm UTC](https://forum.freecodecamp.org/t/js-help-uncaught-syntaxerror-unexpected-token/424369/2 "2020-10-06T16:35:35Z")

</div>

Putting an opening brace (`{`) on the same line as your call to the `openMenu` function is causing the problem. Separating code blocks with braces is not commonly used in JavaScript, but you can do it. You’ll just want a semicolon (`;`) after `openMenu()` and to put that brace on its own line for readability.

---

<div class="post-metadata">

**Author:** ![m.manuel.6.mm](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/m.manuel.6.mm/32/182792_2.png) [@m.manuel.6.mm](https://forum.freecodecamp.org/u/m.manuel.6.mm)\
**Post date:** [October 6, 2020, 4:49pm UTC](https://forum.freecodecamp.org/t/js-help-uncaught-syntaxerror-unexpected-token/424369/3 "2020-10-06T16:49:49Z")

</div>

Hi Ariel, I tried as you say but it doesn’t work anyway because when I go to put the semicolon after `openMenu()` the error becomes `Uncaught ReferenceError: openMenu is not defined.`  
Am I not breaking the function definition if I put the semicolon after `openMenu()`?

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [October 6, 2020, 4:58pm UTC](https://forum.freecodecamp.org/t/js-help-uncaught-syntaxerror-unexpected-token/424369/4 "2020-10-06T16:58:05Z")

</div>

Well, that would happen if you haven’t defined the function `openMenu` anywhere.

---

<div class="post-metadata">

**Author:** ![CactusWren2020](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/cactuswren2020/32/144687_2.png) [@CactusWren2020](https://forum.freecodecamp.org/u/CactusWren2020)\
**Post date:** [October 6, 2020, 5:09pm UTC](https://forum.freecodecamp.org/t/js-help-uncaught-syntaxerror-unexpected-token/424369/5 "2020-10-06T17:09:28Z")

</div>

1. define the function

```auto
function hello() { console.log("hello, friend");

```

1. assign the function to the click property

```auto
button.onclick = hello;

```

1. now, when you click:

```auto
//hello, friend

```

Some variations:  
anonymous function

```auto
button.onclick = function() {console.log("hello, friend")}

```

event-listener (I only use this one)

```auto
button.addEventListener("click", hello);
//or
button.addEventListener("click", function() {console.log("hello, friend")})

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 12:33pm UTC](https://forum.freecodecamp.org/t/js-help-uncaught-syntaxerror-unexpected-token/424369/6 "2021-06-01T12:33:51Z")

</div>

Closed on June 1, 2021, 12:33pm UTC


