I cannot identify what’s wrong with my code:
Hey there:
@Anshu_Gupta I’m not sure exactly why, but somehow the .src
on line 14 of your code is not being read properly. When I deleted it and rewrote it, it worked for me, so try that.
@balajietr If you copy/paste code from the forum that is not code-formatted by backticks ```, the quotes will get messed up, and you’ll have to fix them manually.
This is code-formatted:
let animal = 'cat'
This is not code-formatted:
let animal = ‘cat’
To get your code to work, change all the quotation marks to single, double or backtick quotation marks.
Hope this helps!
Ben
But I have NOT copy/paste anything and i tried fixing by deleting it and rewriting it but it did not work for me i dont know why…
Hey there. Happy to help!
At line 15, you have wrote .textContent(animal[2])
instead of .textContent = animal[2]
. Since .textContent
does not have parentheses ()
, try replacing it with .textContent = animal[2]
.
Hope this helps!
Pummarin
Ok thanks it worked for me
import { animals } from ‘animalShelter.data’;
let title = document.createElement(‘h1’);
title.textContent = ‘Adoptable Animals’;
document.body.appendChild(title);
for (let animal of animals) {
let animalName = document.createElement('h2');
animalName.textContent = animal[0];
document.body.appendChild(animalName);
let picture = document.createElement('img');
img.src = animal[1];
document.body.appendChild(picture);
let description = document.createElement('paragraph');
description.textContent = animal[2];
document.body.appendChild(description);
}
Please find my mistake. It says Make sure the order of the elements inside the loop is h2
, img
, then p
.
import { animals } from ‘animalShelter.data’;
let title = document.createElement(‘h1’);
title.textContent = ‘Adoptable Animals’;
document.body.appendChild(title);
for (let animal of animals) {
let animalName = document.createElement('h2');
animalName.textContent = animal[0];
let picture = document.createElement('img');
picture.src = animal[1];
let description = document.createElement('p');
description.textContent = animal[2];
document.body.appendChild(animalName);
document.body.appendChild(picture);
document.body.appendChild(description);
}
Solution =)
import { animals } from ‘animalShelter.data’;
let title = document.createElement(‘h1’);
title.textContent = ‘Adoptable Animals’;
document.body.appendChild(title);
for (let animal of animals) {
let animalName = document.createElement('h2');
animalName.textContent = animal[0];
document.body.appendChild(animalName);
let picture = document.createElement('img')
.src = animal[1]
document.body.appendChild(picture)
let description = document.createElement('p')
description.textContent = animal[2]
document.body.appendChild(paragraph)
}
what i am missing?
_me_hand: