Learn with Yasir
Share Your Feedback

Find & Fix JavaScript Mistakes: Beginner Practice Exercises

Sharpen your JavaScript skills by identifying and correcting common coding errors with these beginner-friendly practice exercises.

๐Ÿงช Fix & Find Questions

๐ŸŸข Beginner Fix & Find

  1. Identify and fix the mistake in the following code:

    <script>
      function greet() {
        alert("Welcome to JavaScript!"
      }
      greet();
    </script>
    

    Hint: ๐Ÿ’ก Check the syntax of the function, especially parentheses and braces.

    ๐Ÿ” View Issue & Fixed Solution

    Issue: The closing parenthesis and semicolon are missing from the alert statement.

    โœ… Fixed Solution

    <script>
      function greet() {
        alert("Welcome to JavaScript!");
      }
      greet();
    </script>
    

  2. Identify and fix the mistake in the following code:

    <script>
      var name = prompt("What is your name?")
      alert("Hello, " + name)
    </script>
    

    Hint: ๐Ÿ’ก Always terminate statements with a semicolon in JavaScript.

    ๐Ÿ” View Issue & Fixed Solution

    Issue: Missing semicolons at the end of statements.

    โœ… Fixed Solution

    <script>
      var name = prompt("What is your name?");
      alert("Hello, " + name);
    </script>
    

  3. Identify and fix the mistake in the following code:

    <script>
      alert(Welcome to JavaScript);
    </script>
    

    Hint: ๐Ÿ’ก Text inside alert should be in quotes.

    ๐Ÿ” View Issue & Fixed Solution

    Issue: The string is not wrapped in quotation marks.

    โœ… Fixed Solution

    <script>
      alert("Welcome to JavaScript");
    </script>
    

  4. Identify and fix the mistake in the following code:

    <script>
      document.getElementById("message").innerHtml = "Hello World!";
    </script>
    

    Hint: ๐Ÿ’ก JavaScript property names are case-sensitive.

    ๐Ÿ” View Issue & Fixed Solution

    Issue: innerHtml is incorrect; it should be <b>innerHTML</b>.

    โœ… Fixed Solution

    <script>
      document.getElementById("message").innerHTML = "Hello World!";
    </script>
    

  5. Identify and fix the mistake in the following code:

    <script src="script.js">
      alert("This won't work!");
    </script>
    

    Hint: ๐Ÿ’ก Avoid mixing inline script content when using the `src` attribute.

    ๐Ÿ” View Issue & Fixed Solution

    Issue: When using the `src` attribute in the script tag, inline code inside it is ignored.

    โœ… Fixed Solution

    <script src="script.js"></script>
    <!-- Or remove src and include the code inline -->
    <script>
      alert("This won't work!");
    </script>
    

๐ŸŸก Intermediate Fix & Find

๐Ÿ”ด Advanced Fix & Find

๐Ÿ“š Related Resources


๐Ÿง  Practice & Progress

Explore More Topics