D
D
Denis3382015-10-12 23:57:18
JavaScript
Denis338, 2015-10-12 23:57:18

Why is undefined displayed instead of a space?

function calculate(){
var str=document.getElementById("vvodA").value;

var i=0;
var s=new String(s);
var s1=new String(s1);
while (i<str.length)

{
  if (str.charAt(i)!=' ') {
    s+=str.charAt(i);
    i++;
    }
  else 
  {
    i++;
    s1=s;
    s=' ';
  }
  
}
s=s.concat(s1);
alert(s);
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2015-10-13
@Denis338

var s=new String(s);
var s1=new String(s1);
it's not easier to do this:
var s= "",
s1= "";
I don't know what this new String is but I can assume that it should be like this var s1=new String("s1");

I
Ivan Volkov, 2015-10-13
@oOLokiOo

Well, at least bring your code, for the sake of decency and so as not to be telepaths)
It is obvious that you are clearly “shove something wrong” in this line)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question