Hi all,

I am new to programming and therefore have what is probably an elementary problem.

I'll show you the code and then explain the problem.

// A function to check the validity of the user's input
function inputInRange(msg,min,max) {
while(isNaN(msg) || msg<min || msg>max) {
alert ('Your amount was invalid');
var msg = parseInt(prompt(message));
alert('You purchased '+ msg +' tokens.');

// Function that allows the user to purchase tokens
function buyTokens() {
var balObj = document.getElementById("balance");
var msg = parseInt(prompt(message));
balObj.value = parseInt(balObj.value) + parseInt(msg);

Once this code is executed using an invalid value (in order to enter the while loop) the balObj.value is adding the orignal invalid value of msg and not the new value defined in the while loop.

Can anyone see how I can fix it?

Thank you