I don’t understand why it put syntax error, can you help me please ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I don’t understand why it put syntax error, can you help me please ?

https://sololearn.com/compiler-playground/WbS4ROStFzzI/?ref=app Please help me, I try to make something that write the date of today in the middle, the date of the 2 previous day at left, and the date of the 2 next day at right The fact that all the five div does not enter in the body length is normal, my error is in the JavaScript code, in the jour function You can ask me question if you don’t understand what a line of code is supposed to do, I didn’t put any comment Thank you

2nd Apr 2024, 8:17 PM
Noam Ganguillin
Noam Ganguillin - avatar
7 Answers
+ 2
First of all you have problem with concatenation, your code: idDate3.innerHTML = semaine[semaine3] +' ' jour3 +' ' + mois[mois3]; Should be: idDate3.innerHTML = semaine[semaine3] +' ' +jour3 +' ' + mois[mois3]; (add a concatenation operator between jour3 and ' ') Secondly, your entire JavaScript should be in the onload function “window.onload = ()=>{ //your content }” else saving elements in those variables won't work as that code will be trying to find an element before the DOM is loaded
2nd Apr 2024, 10:48 PM
IAmSupreme
IAmSupreme - avatar
0
Ok, thank you so much !
3rd Apr 2024, 3:14 PM
Noam Ganguillin
Noam Ganguillin - avatar
0
It work now !
3rd Apr 2024, 3:15 PM
Noam Ganguillin
Noam Ganguillin - avatar
0
And also, try to update your codes to ES6 syntax, JavaScript developers don't use "+" for concatenation again... We use `
4th Apr 2024, 12:21 PM
AREMU TAOFEEK
0
AREMU TAOFEEK there seem to be a law you've forgotten too, «if it works...», plus it's not like concatenation using “ + ” is abolished, I use it sometimes.🙂
4th Apr 2024, 1:16 PM
IAmSupreme
IAmSupreme - avatar
0
For sur but i havnt learn ES6 so far
4th Apr 2024, 7:55 PM
Noam Ganguillin
Noam Ganguillin - avatar
0
IAmSupreme I know but it's good to be updated
25th Apr 2024, 9:38 AM
AREMU TAOFEEK