mercredi 13 janvier 2016

Variable value changes when used in different files

I have a random variable and alert this variable in one JavaScript file, then do some process with the same value of the random variable in another HTML file. However, it seems that two variable shows different value in two files when I used alert() function to inspect the results in two files.

In JavaScript file, the related code to generate random variable RandomMsg values and alert the random variable Random_Msg:

function CreateRandomMsg() {
    var RandomMsg = Msgs_Arr[Math.floor(Math.random()* Msgs_Arr.length)];
    return RandomMsg;
}

var Random_Msg = CreateRandomMsg();

function alertMsg() {
    alert(Random_Msg);
}

In HTML file, I include this JavaScript file and just use the random variable Random_Msg, however it shows a different message value. I'm not sure which part of the code contains mistake.




Aucun commentaire:

Enregistrer un commentaire