👨‍💻 Daily Code 46 | Random Number 1-100, 🐍 Python and 🟨 JavaScript

Gregor Schafroth - Jan 22 - - Dev Community

Today I had very little time for code, so I wanted to do a very simple exercise: Generate a random number between 1 to 100, and in the case of JS also put that on the website. In both cases I used a bit of ChatGPT to fix this quickly. should do the same exercise again tomorrow and see if I can remember how to do it without!

My Code

Python

# Exercise: Print a random number between 1 and 100

import random

random_number = random.randint(1, 100)
print(random_number)
Enter fullscreen mode Exit fullscreen mode

JavaScript

<!DOCTYPE html>
<html>

<head>
    <title>Random Number Generator</title>
</head>
<body>
    <button id="generateButton">Generate Random Number</button>
    <div id="randomNumber"></div>
    <script>
        document.getElementById("generateButton").onclick = function () {
            let randomNumber = Math.floor(Math.random() * 100) + 1;
            document.getElementById("randomNumber").textContent = randomNumber;
        };
    </script>
</body>

</html>
Enter fullscreen mode Exit fullscreen mode

(Python actually suggested me ‘var’ here, but I don’t think that’s really used anymore, so I changed it to let)

Have a great day everyone, see you tomorrow! 🙋‍♂️

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player