Cover image for Debug Challenge Week 1

Debug Challenge Week 1

micahlt profile image Micah Lindley ・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" >
Enter fullscreen mode Exit fullscreen mode

Please answer in the comments!


Editor 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


Socks should be a const:)

  • u have an extra )

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!