0

can we get output of the string (text) also with the numbers for two variables in the statement 1 ?

for (i=1, text=""; i<=5; i++) { text = i; document.write(i + "<br />"); }

19th Jul 2017, 6:27 AM
Selina Miraz
Selina Miraz - avatar
6 Answers
0
seems like you havent tried it Selina. just try it and see what happens. thats how you learn. if you are not able to solve it, then ask questions
20th Jul 2017, 2:47 AM
Gurpreet Singh
Gurpreet Singh - avatar
0
I don't understand how to imply this: text=i; where i is an integer and text is a string .
20th Jul 2017, 1:18 PM
Selina Miraz
Selina Miraz - avatar
0
if I input some text even it only prints the integer value only for (i=1, text="miraz"; i<=5; i++) { text = i; document.write(i + "<br />"); } output : 1 2 3 4 5
20th Jul 2017, 1:20 PM
Selina Miraz
Selina Miraz - avatar
0
javascript generally auto converts number to string. otherwise use: text = i.toString();
20th Jul 2017, 1:24 PM
Gurpreet Singh
Gurpreet Singh - avatar
0
because you are over writing the value in first line of loop. try text = text + i.toString(); it will concatenate the numbers.
20th Jul 2017, 1:27 PM
Gurpreet Singh
Gurpreet Singh - avatar
0
ok . thanks .
20th Jul 2017, 1:29 PM
Selina Miraz
Selina Miraz - avatar