0

Hello again :)

I am having a problem where I want to change a particular variable based on what parameters I send to a js function.

In the code below, dnum is a number 1-6, and I want the global variable d1keep (or d2keep, d3keep etc.) to equal the dvalue.

function KeepDie(dnum, dvalue) {
	d+dnum+keep=dvalue;

         ... (more code)
}

I've tried using single quotes, double quotes, brackets, curly brackets, parentheses, and other punctuation in many locations all over that line of code, but I cannot get it to work.

Please help, thanks!

4
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by Airshow
0

Hello again :)

I am having a problem where I want to change a particular variable based on what parameters I send to a js function.

In the code below, dnum is a number 1-6, and I want the global variable d1keep (or d2keep, d3keep etc.) to equal the dvalue.

function KeepDie(dnum, dvalue) {
	d+dnum+keep=dvalue;

         ... (more code)
}

I've tried using single quotes, double quotes, brackets, curly brackets, parentheses, and other punctuation in many locations all over that line of code, but I cannot get it to work.

Please help, thanks!

Pretty simple actually:

function KeepDie(dnum, dvalue) {
	window["d"+dnum+"keep"] = dvalue;

         ... (more code)
}
0

Thanks a lot, I'm finding the use of the window array is extraordinarily useful.

0

Thanks a lot, I'm finding the use of the window array is extraordinarily useful.

It's not an array, that's important to understand, it's a object.
In javascript obj.name is equivalent to obj["name"] .

0

Thanks for the lesson, I'm still trying to visualize the whole object thing. Knowing that window is an object helps. Learning how to code and understanding it all are sometimes different things; certainly they are for me with regards to javascript.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.