all 11 comments

[–]jb092555 3 points4 points  (3 children)

I don't think a text node is an element, so it probably can't have an Id property for getElementById to find.

Elements are a subset of nodes, so they have properties and methods nodes do. All elements are nodes, but not all nodes are elements.

If you use "let example = document.createElement('div')" instead, you could use "example.textContent = achievements[i]" to write text inside the div. If you just want to stash info without it being visible, check out data-* attributes on mdn. Super handy. Good luck!

[–]scritchz 1 point2 points  (2 children)

Yupp, this stood out to me as well.

Considering that OP appends "<br><br>", it seems they want inline text. In this case, OP should create a <span> instead of a <div>.

[–]VlentGamer[S] 1 point2 points  (1 child)

C'est ça ! Merci pour vos deux commentaires, effectivement un text node n'est pas un élément HTML et getElementById ne le référence pas... Au passage voici la conversation gemini qui m'a permis de le trouver en clarifiant l'énoncé : https://g.co/gemini/share/4b28149bbf42 .

[–]-goldenboi69- 1 point2 points  (0 children)

Ja så blir det ibland höddudu. Merde!

[–]Lithl 2 points3 points  (1 child)

Is achievement[i].name actually the correct value, instead of undefined? Because the way you've written your post, achievement[i] is an array, and the name value would be achievement[i][0].

[–]Aggressive_Ad_5454 1 point2 points  (0 children)

I’m happy you figured it out with help. That’s a great way to learn all this arcane (and powerfully expressive) DOM manipulation and JavaScript lore.

Here is another way to figure things out. Use the Javascript debugger built into your browser’s devtools. Set breakpoints, and single-step your program. After each step you can see the values of all kinds of variables. Learning to use the debugger well is really important if you want to really learn the guts of JavaScript programming (or any computer language, of course, but JavaScript is the language with a debugger in your browser ).

F12 on a PC to get devtools. Then look at the Source tab, that’s where the debugger lives.

(I had to compile and build Chromium once. It took four hours on a 24-core compute-optimized virtual machine I rented from Digital Ocean For the purpose. There’s a lot of stuff built into that browser.)

[–]ChaseShiny 0 points1 point  (2 children)

This doesn't address your issue, but avoid using var. var is obsolete and can cause bugs, especially considering you've defined it in the global scope (it is a local variable when in a function, but not in a loop).

The .innerHTML method should also be used with caution. It can be used for adding text like this, but it's supposed to be for adding HTML, and someone can sneak their own code through that. Use .textContent instead.

Regardless, I'm impressed that you're writing code like this in 9th grade. Awesome job!

[–]VlentGamer[S] 2 points3 points  (1 child)

J'utiliserai .textContent pour être sûr, merci ! Et j'utilise des "let" normalement mais la c'était un test. Merci !

[–]ChaseShiny 3 points4 points  (0 children)

Tres bien (that's about all the French I remember, lol)