james909 Posted July 19, 2013 Share Posted July 19, 2013 Here is my code inside a function(): for (var i=1; i<6; i++) { for (var j=1; j<11; j++) { if (h" + i + "w" + j" == "t") { var build = "Bulk"; } if (h" + i + "w" + j" == "z") { var build = "Master"; } if (h" + i + "w" + j" == "T") { var build = "Storage"; } parambuild = parambuild+build; } } I am atempting to get check what letters globally declared vars: h1w1, h1w2, h1w3, h1w4 .... etc .... to h5w10 contain and then make a string such as: BulkMasterBulkBulkStorageBulk But in the current code the string contains: undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedun...... Quote Link to comment https://forums.phpfreaks.com/topic/280308-how-do-i-use-the-incrementing-values-from-a-loop-inside-an-if-statement/ Share on other sites More sharing options...
cyberRobot Posted July 19, 2013 Share Posted July 19, 2013 First, you'll need to recheck the double quotes in the if statements. Afterwards, the following link may help: http://www.sitepoint.com/forums/showthread.php?571957-quot-dynamic-quot-i-variable-names-in-javascript Quote Link to comment https://forums.phpfreaks.com/topic/280308-how-do-i-use-the-incrementing-values-from-a-loop-inside-an-if-statement/#findComment-1441383 Share on other sites More sharing options...
Irate Posted July 20, 2013 Share Posted July 20, 2013 You are comparing a string to another string, h1w1 will never equal t. If you want to compare to a global variable, declare the variable as property of the window object and compare again. Quote Link to comment https://forums.phpfreaks.com/topic/280308-how-do-i-use-the-incrementing-values-from-a-loop-inside-an-if-statement/#findComment-1441518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.