lundi 27 mai 2019

How to generate one random value, and its result from a list

My situation seems to be easy but I can't get it to work...

What I want is, generate a random value displayed in a h tag, and also, display the good value relative to the random one, in an other tag.

var first = ['1+2', '10+20', '100+200'];
var second = ['3', '30', '300'];

var first_value = first[Math.floor(Math.random()*first.length)];
var second_value = second[Math.floor(Math.random()*second.length)];

document.getElementById('first_value').innerHTML = first_value;
document.getElementById('second_value').innerHTML = second_value;

At the moment, everything is generated randomly, there is no relation between the 2 values generated.

If "10+20" is randomly selected, I want to display "30" in the second html tag.

Thanks for your help guys :-)




Aucun commentaire:

Enregistrer un commentaire