DEV Community

Cover image for Debug Challenge Week 1
Micah Lindley
Micah Lindley

Posted on

Debug Challenge Week 1

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))
  }
 </script>
 <input type="button" value="Click me!" onclick="displaymessage" >
Enter fullscreen mode Exit fullscreen mode

Please answer in the comments!

Top comments (6)

Collapse
 
coolshaurya profile image
Shaurya

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}`))
  }
 </script>
 <input type="button" value="Click me!" onclick="displaymessage()" >

Also consider replacing onclick with addEventListener

Collapse
 
mateiadrielrafael profile image
Matei Adriel • Edited

Socks should be a const:)

  • u have an extra )
Collapse
 
micahlt profile image
Micah Lindley • Edited

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

Collapse
 
horacehylee profile image
Horace Lee • Edited
  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))
Collapse
 
ofsazib47 profile image
Omar Faruk Sazib

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

Collapse
 
mateiadrielrafael profile image
Matei Adriel

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