views:

58

answers:

3

I have the following code:

function header(){
 experience += '';
 var expimage = '';
 for(var cik=0;cik<experience.length;cik++){
  switch(experience[cik]){
   case '0':
   expimage += 'img0';
   break;
   case '1':
   expimage += 'img1';
      break;
      case '2':
      expimage += 'img2';
      break;
      case '3':
      expimage += 'img3';
      break;
      case '4':
      expimage += 'img4';
      break;
      case '5':
      expimage += 'img5';
      break;
      case '6':
      expimage += 'img6';
      break;
      case '7':
      expimage += 'img7';
      break;
      case '8':
      expimage += 'img8';
      break;
      case '9':
      expimage += 'img9';
      break;
  }
 }
 document.getElementById('level').innerHTML = expimage;
 alert(expimage);
}

But it only work on chrome or mozilla. It shows up an empty alert box, but it work on firefox and chrome. I tried to alert each variable after each line, and I noticed that the problem shows when I tried to alert(experience[0]) ,it shows undefined, the other steps are working.

A: 

Hi,

Could you show the full code and HTML so I can see how you are calling this method and how 'experience' is defined?

Also, It looks like you could replace your switch statement with this:

expimage += 'img' + experience[cik];
J Higs
This should be a comment, not an answer.
apphacker
I found the problem:IE can`t split a string to it`s characters because i tried to alert experience[0] and it says undefined....
coolboycsaba
but i don`t know how to solve it...
coolboycsaba
@coolboycsaba Edit your question to include this new information, and you may receive a better answer.
meagar
Have you tried experience.charAt(0)?
J Higs
A: 

The variable experience doesn't seem to be defined anywhere before it is used. You probably want to pass it into the function as an argument; you can modify your function to accept the argument like this:

function header(experience) {
    // ....
}

Without more information on what experience is and the code that is calling header, it's difficult to answer your question more thoroughly.

meagar
i don`t think this is the problem because if i alert the experience it works, the problem is only when I want to split it into characters
coolboycsaba
A: 

Thanks for everyone ! the charAt(cik) worked well. :D

coolboycsaba