Debug Challenge Week 1

github logo ・1 min read

It’s that time, guys! The Debug Challenge has begun! Keep in mind, mildly skilled devs can probably skip this as this weeks’s challenge is oriented toward beginners. Here we go!

What’s wrong with this code?

Not just what’s broken; also what’s depreciated or just impolite syntax. The language for this week is JavaScript.

<script type="text/javascript">
  function displaymessage {
    var socks = "3"
    alert(join("You have this many socks, plus 6: " + socks + 6))
 <input type="button" value="Click me!" onclick="displaymessage" >

Please answer in the comments!

twitter logo DISCUSS (6)
markdown guide

According to me the code should be -

<script type="text/javascript">
  function displaymessage() {
    let socks = 3
    alert(`You have this many socks, plus 6: ${socks +6}`))
 <input type="button" value="Click me!" onclick="displaymessage()" >

Also consider replacing onclick with addEventListener


Nice answer, and great job using the variable inside the string! However, you do have an extra parenthesis on line 4. :D

  1. displaymessage should have bracket () at the end on line 2.

  2. join function is undefined, replace line 4 with

    alert("You have this many socks, plus 6: " + (socks + 6))

The on click event should also be onclick="displaymessage()" instead of onclick="displaymessage"


You could also set the onclick prop of the element in js to that function!

Classic DEV Post from Jun 13

Async, Parallel, Concurrent Explained - Starring Gordon Ramsay

Complex computing concepts simplified

Micah Lindley profile image
I’m a self-taught teen designer, developer, and writer. I host the Debug Challenge! Timezone: CST | Age: 15 | Gender: Male

Don't ghost on us ❤️