Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
2
Indexable
Never
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Buggy JavaScript Example</title>
</head>
<body>
    <h1>Addition Calculator</h1>
    <form>
        <label for="num1">Number 1:</label>
        <input type="number" id="num1" name="num1">
        <br><br>
        <label for="num2">Number 2:</label>
        <input type="number" id="num2" name="num2">
        <br><br>
        <button type="button" onclick="addNumbers()">Add Numbers</button>
    </form>
    <h2>Result: <span id="result"></span></h2>

    <script>
    function addNumbers() {
        let num1 = document.getElementById("num1").value;
        let num2 = document.getElementById("num2").value;

        // There is a syntax error in the next line
        var result = num1 + num2;

        // There is a logical error in the next line
        document.getElementByID("result").innerHTML = result;
    }
    </script>
</body>
</html>