DEV Community

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

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

Gregor Schafroth on January 22, 2024

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 a...
Collapse
 
kaamkiya profile image
Kaamkiya

Since you're not changing the value of randomNumber after initialising it, you can also use const, which is preferred over let. (Constants are good.)

I'm curious, why did you use .textContent instead of .innerText? Is there a difference?

Collapse
 
gregor_schafroth profile image
Gregor Schafroth • Edited

@kaamkiya hi again!
const / let: good point. Since I learned to program with Python first I am not used to making that distinction. I guess I should just always use const and then just change them to let if I run into some kind of issue with that.

.textContent / .innerText : I actually never heard about .innerText. What I saw in some tutorials was the use of .innerHTML , but I figured that .textContent would probably be the safer option if I'm not inserting any html tags. Do you think .innerText would be even better to use?

Collapse
 
kaamkiya profile image
Kaamkiya

I don't know, I've only seen textContent used twice, but same with innerText. I doubt it matters, it's likely that one is just a reference to the other.