What's wrong with my code? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

What's wrong with my code?

HTML code <table border="solid" id="A"> <tr><th>Int1</th><th>Int2</th><th>Int3</th></tr> <tr><td>1</td><td>2</td><td>3</td></tr> </table> JS code let a=document.getElementById("A"); let b=a.elements.Int2.value console.log(b) <!--It says elements is an error in the code. (This was from Introduction to JavaScript, Unit 3, lesson 2, known as Advanced User Input)-->

19th May 2024, 12:53 AM
Kongpheng Lo
Kongpheng Lo - avatar
10 Antworten
+ 1
Kongpheng Lo it works, just put the code between the script tag. <script> let table = document.getElementById("A"); let cellValue = table.rows[1].cells[1].textContent; // Access the second cell in the second row console.log(cellValue); </script>
20th May 2024, 7:24 PM
Chris Coder
Chris Coder - avatar
+ 1
How are you running your code? Are you using the code playground?
22nd May 2024, 3:24 AM
Chris Coder
Chris Coder - avatar
0
I copied the text into my JavaScript code (I did not include the "Try this:" part in the code) and it says rows is the error in the code.
19th May 2024, 12:33 PM
Kongpheng Lo
Kongpheng Lo - avatar
0
How come it works in script, but not in JavaScript?
20th May 2024, 10:19 PM
Kongpheng Lo
Kongpheng Lo - avatar
0
That is how you use Javscript internaly in your HTML document.
20th May 2024, 10:36 PM
Chris Coder
Chris Coder - avatar
0
I know, but why does it not work externally?
21st May 2024, 10:06 PM
Kongpheng Lo
Kongpheng Lo - avatar
0
Ok, I'll recheck the lesson that talks about internal and external JavaScript.
22nd May 2024, 12:15 AM
Kongpheng Lo
Kongpheng Lo - avatar
0
I am still confused, but I now know that inline and internal JS code is in the .html file, while external JS code is in the .js file. I didn't think about files. Can I get some explain of how it being in a .js or .html file is different? I should understand why and it could help a lot.
22nd May 2024, 12:26 AM
Kongpheng Lo
Kongpheng Lo - avatar
0
Yea. Btw, I forgot to tell you guys that I'm only on introduction on JavaScript currently.
22nd May 2024, 7:33 PM
Kongpheng Lo
Kongpheng Lo - avatar
0
I just finished Introduction to JavaScript :p
22nd May 2024, 9:53 PM
Kongpheng Lo
Kongpheng Lo - avatar