vendredi 8 novembre 2019

Is there a way to make a random number in JavaScript and then take it and use it to make another random number?

Forgive me if my question is not that clear, but I'm trying my best (english is not my native language).

I'm making a website for a fake company. One of the sections has a 'Stock Quote' feature that is just a random number. For this, I use the following code:

<p id="stockcurrent"></p>

<script>
document.getElementById("stockcurrent").innerHTML =
Math.floor(Math.random() * 500) + 200;
</script>

Now, what I want to do, is to take the number generated for that and use it to create a new number, that has as condition that it has to be equal or larger than the generated number. ie, something like this:

<p id="stockdayhigh"></p>

<script>
document.getElementById("stockdayhigh").innerHTML =
Math.floor(Math.random() * 500) + (the result of the stockcurrent script);
</script>

Is this something possible to do? My knowledge of JS is pretty basic. Thanks for any help!




Aucun commentaire:

Enregistrer un commentaire