/    Sign up×
Community /Pin to ProfileBookmark

switch not setting new value – why?!

I can’t seem to get the following code to set a new value for the var nClass. It should return “ad” in this example, yet it returns undefined – why?

[CODE]
function cardClass(tmp) {
var na=tmp.split(“:”);
var pfx=na[0];
var sfx=na[1];
var nClass;
switch(pfx) {
case 2: nClass=’a’+sfx; break;
case 3: nClass=’b’+sfx; break;
case 4: nClass=’c’+sfx; break;
case 5: nClass=’d’+sfx; break;
case 6: nClass=’e’+sfx; break;
case 7: nClass=’f’+sfx; break;
case 8: nClass=’g’+sfx; break;
case 9: nClass=’h’+sfx; break;
case 10: nClass=’i’+sfx; break;
case 11: nClass=’j’+sfx; break;
case 12: nClass=’k’+sfx; break;
case 13: nClass=’l’+sfx; break;
case 14: nClass=’m’+sfx; break;
}
return nClass;
}

document.write( cardClass(“2:d”) );
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Mar 17.2006 — You are comparing a string to a number.

Eric
Copy linkTweet thisAlerts:
@LAwebTekauthorMar 17.2006 — I get it...duh, lol!

thank you very much for the quick reply
×

Success!

Help @LAwebTek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...