DEV Community

Cover image for πŸ‘¨β€πŸ’» Daily Code 48 | Random Number 1-100, 🐍 Python and 🟨 JavaScript (3)
Gregor Schafroth
Gregor Schafroth

Posted on

1

πŸ‘¨β€πŸ’» Daily Code 48 | Random Number 1-100, 🐍 Python and 🟨 JavaScript (3)

alright as promised yesterday I’m going to try making the Random Number Generator HTML again today without looking up anything or using any ChatGPT. I already solved that for Python yesterday, so now it’s just JS left

My Code

Tadaa! Turns out this time I was able to solve it fully on my own!

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>1-100 Random Generator Button</title>
</head>

<body>
    <button id="js-random-button">Generate Random Number</button>
    <div id="js-random-number"></div>

    <script>
        document.getElementById('js-random-button').onclick = function () {
            let randomNumber = Math.floor(Math.random() * 100) + 1;
            document.getElementById('js-random-number').textContent = randomNumber;
        }
    </script>
</body>

</html>
Enter fullscreen mode Exit fullscreen mode

Next I want to get more reps with page manipulation.

I want to become so familiar with this that I can control website content with JavaScript without even thinking much, so I’ll add more exercises to achieve this in the coming days.

Tiugo image

Modular, Fast, and Built for Developers

CKEditor 5 gives you full control over your editing experience. A modular architecture means you get high performance, fewer re-renders and a setup that scales with your needs.

Start now

Top comments (2)

Collapse
 
_ndeyefatoudiop profile image
Ndeye Fatou Diop β€’

Way to go πŸ‘. Small thing: if there is no element found, this code will fail. So it’s good practice to check that the element actually exists and handle that case 😌

Collapse
 
gregorschafroth profile image
Gregor Schafroth β€’

Thanks! Mhh okay cool makes sense, will try to do that next time πŸ˜„

Neon image

Next.js applications: Set up a Neon project in seconds

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started β†’

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere β€œthank you” often brightens someone’s dayβ€”share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay