Jump to content

How do I use the incrementing values from a Loop inside an If statement


james909

Recommended Posts

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......

 
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.