Variables all null

so I’m trying to make a random number generator that takes 2 numbers the user gives it and makes a random number within that range, however it seems none of the variables are given values, the code will be below:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="stylesheet.css">
    </head>
    <body>
        <div>
            <input type="text" id="number_a" class="range"> 
            <input type="text" id="number_b" class="range">
            <button class="button" onclick="generateRandomNumber()">Generate random number</button>
            <h1 id="randomNumber">Random number will generate here</h1>
        </div>
    </body>
    <script type="text/javascript" src="script.js">
    function generateRandomNumber() {
        var a = document.getElementById('number_a').value
        var b = document.getElementById('number_b').value
        var random = Math.random(a, b)
        document.getElementById(randomNumber).innerHTML = 'random'
        console.log(a, b, random)
    }
    </script>
</html>

also it gives me an error in the console that says
“Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML’)”

Put quotes around the argument being passed into getElementById.

1 Like

thank you I can’t believe I didn’t notice, I appreciate your help!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.