My code:
document.addEventListener("DOMContentLoaded", function () {
document.querySelector("#y").onclick = () => {
y = [
{ name: "A", adult: true },
{ name: "B", adult: false },
];
y.forEach((person) => {
para = document.createElement("p");
document.querySelector("#add").append(para);
para.innerHTML = `${person.adult}`;
if (`${person.adult}`) {
para.style.color = "red";
console.log(`${person.adult}`);
}
});
};
});
Here, when person's adult property is true, then and only then it should colored the text red. But both times, the person's adult property is true or false, it colors the text red.
HOW TO FIX THIS PROBLEM ?
Aucun commentaire:
Enregistrer un commentaire