+ 1
Can someone tell me what's the problem in this code?
var c1 = ["HTML", "CSS"]; var c2 = ["JS", "C++"]; var courses = c1.concat(c2); var i=0; for(;i<courses.lenght;i++){ document.write(courses[i]);}
10 Answers
+ 7
Parmesh Kumawat , what i wanted to say is, that using a tag with the name of the language helps people get an idea what the question or problem is, and what language is used. Most people who are here in the forum are not at the same level of knowlege regarding different programming languages. So they can see at a glance, if they should go on reading in detail or skip.
+ 5
Parmesh Kumawat I would also suggest changing var to let and add a space on the document.write to separate the full array on view
let c1 = ["HTML", "CSS"];
let c2 = ["JS", "C++"];
let courses = c1.concat(c2);
let i=0;
/* change length */
for(;i<courses.length;i++){
document.write(courses[i]," ");}
°The main difference is the scope difference, while let can be only available inside the scope it's declared, like in for loop, var can be accessed outside the loop for example. ... let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used.
ref: stackoverflow
+ 5
Parmesh Kumawat , please use appropriate tags for programming language. Thanks!
+ 3
Parmesh Kumawat , you typed "lenght", change it to "length".
+ 3
Sometimes the problem just starts with misspelling of codes.
+ 2
Yeah it worked thanks didn't see that stupid mistake. Cost me hoursđđ
+ 2
Parmesh Kumawat he meant like how you have arrays as your tag above
+ 1
Lothar can u please elaborate it, I didn't understand? Thanks!
+ 1
Length spelling wrong check your code