+ 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]);}

18th Jul 2020, 4:52 PM
Parmesh Kumawat
Parmesh Kumawat - avatar
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.
19th Jul 2020, 1:55 PM
Lothar
Lothar - avatar
+ 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
18th Jul 2020, 5:03 PM
BroFar
BroFar - avatar
+ 5
Parmesh Kumawat , please use appropriate tags for programming language. Thanks!
18th Jul 2020, 5:21 PM
Lothar
Lothar - avatar
+ 3
Parmesh Kumawat , you typed "lenght", change it to "length".
18th Jul 2020, 4:56 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
Sometimes the problem just starts with misspelling of codes.
20th Jul 2020, 5:17 AM
Ahmad Sha. Habibi
Ahmad Sha. Habibi - avatar
+ 2
Yeah it worked thanks didn't see that stupid mistake. Cost me hours😑🙄
18th Jul 2020, 4:59 PM
Parmesh Kumawat
Parmesh Kumawat - avatar
+ 2
Parmesh Kumawat he meant like how you have arrays as your tag above
18th Jul 2020, 5:30 PM
BroFar
BroFar - avatar
+ 1
Lothar can u please elaborate it, I didn't understand? Thanks!
18th Jul 2020, 5:27 PM
Parmesh Kumawat
Parmesh Kumawat - avatar
+ 1
Length spelling wrong check your code
19th Jul 2020, 4:28 AM
shubham kumar
shubham kumar - avatar