+ 1
I tried to output data from my array in a div with id="container" but it is not working. Can anyone please help me to fix it?
Thanks in advance and here is the code var markup = function(name, email, country){ return ` <div class="card"> ${name} <br> ${email} <br> ${country} </div> `; }; var data = [ { name: "Ryan Zico", email: "htmlcssjs@gmail.com", country: "Philippines" } ]; var container = document.getElementById("container"); for(var i = 0; i < data.length; i++) { container.innerHTML += markup(data[i].name, data[i].email, data[i].country) }
14 Respuestas
+ 2
Here is the link
https://code.sololearn.com/W2nQJ5ULVF3r/?ref=app
+ 2
Ipang I thought it might be something like that. Ryan Zico (Challenge Me) what version of the app do you have? Can you try it on a modern browser to see if you still get an error?
Anyway, line 12 is where the backticks start which as we know is ES6, but if Ryan changed var markup to const markup, then line 11 would've errored.
+ 2
I'm using version 3.4.4
Thats what my phone can hold because i installed it from the play store
+ 2
In my (previously) older phone which had a thing with ES6, I couldn't even use `let` without having the app to yell at me.
+ 1
Can you post a link to your code? I'm wondering if you have the HTML set up right. Also, you may be calling the Java code too early (before the DOM has loaded).
+ 1
It looks like it's working. Your array has 1 object with 3 key-value pairs. I see all 3 values being outputted within a div on the screen.
What were you expecting?
+ 1
But its not working here
Console says:
Uncaught Syntax Error
Unexpected token ILLEGAL
Line: 12
+ 1
It's working for me. I just copied your code into a new code but just to double check.
Can you try this one to see if you're still getting an error in the console?
https://code.sololearn.com/Wu2156B4HIdA/?ref=app
+ 1
Ryan,
What happens if you replace all `var` in the script by `let`? does it work?
+ 1
I will try that
+ 1
Console still says same
+ 1
Ryan,
I was guessing maybe your device doesn't fully support ES6. String interpolation came with ES6, but changing `var` to `let` doesn't seem to be causing any problem. So my guess maybe wrong.
+ 1
Oooh
So its all from my phone
Thanks for the tip
+ 1
Ryan,
Which Android version in the phone?
Or is it using iOS?