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

8th Apr 2021, 3:43 PM
Zico
Zico - avatar
14 Answers
8th Apr 2021, 3:58 PM
Zico
Zico - avatar
+ 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.
8th Apr 2021, 4:56 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 2
I'm using version 3.4.4 Thats what my phone can hold because i installed it from the play store
8th Apr 2021, 5:00 PM
Zico
Zico - avatar
+ 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.
8th Apr 2021, 5:02 PM
Ipang
+ 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).
8th Apr 2021, 3:51 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 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?
8th Apr 2021, 4:11 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 1
But its not working here Console says: Uncaught Syntax Error Unexpected token ILLEGAL Line: 12
8th Apr 2021, 4:18 PM
Zico
Zico - avatar
+ 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
8th Apr 2021, 4:32 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 1
Ryan, What happens if you replace all `var` in the script by `let`? does it work?
8th Apr 2021, 4:40 PM
Ipang
+ 1
I will try that
8th Apr 2021, 4:44 PM
Zico
Zico - avatar
+ 1
Console still says same
8th Apr 2021, 4:44 PM
Zico
Zico - avatar
+ 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.
8th Apr 2021, 4:49 PM
Ipang
+ 1
Oooh So its all from my phone Thanks for the tip
8th Apr 2021, 5:22 PM
Zico
Zico - avatar
+ 1
Ryan, Which Android version in the phone? Or is it using iOS?
8th Apr 2021, 5:24 PM
Ipang