how do I tell JS to createElement('p') that says survived if a boolean array value in a JSON says "1" and if it says "0" to say deceased? **I need it to create that p element that says "survived" if it the value "survived" in the JSON says 1 or "deceased" if it says 0. This is one of the many people in the JSON:
'use strict';
let passengers = [{
"PassengerId": 1,
"Survived": 0,
"Pclass": 3,
"Name": "Braund, Mr. Owen Harris",
"Sex": "male",
"Age": 22,
"SibSp": 1,
"Parch": 0,
"Ticket": "A/5 21171",
"Fare": 7.25,
"Cabin": "",
"Embarked": "S"
},
//this is my DOM js:
'use strict';
const seccCards = document.querySelector('#sctCards');
const inputFiltro = document.querySelector('#txtFiltro');
const imprimirCards = () => {
seccCards.innerHTML = '';
let filtro = inputFiltro.value.toLowerCase();
passengers.forEach(obj_passenger => {
if (obj_passenger.Name.toLowerCase().includes(filtro) || obj_passenger.PassengerId.toLowerCase().includes(filtro)) {
let card = document.createElement('div');
card.classList.add('card');
let passengerbeen = document.createElement('h2');
passengerbeen.innerText = obj_passenger.Name;
let passengerF = document.createElement('p');
if (obj_passenger.Survived == 1) {
passengerF = sobrevivio;
} else {
passengerF = fallecido;
}
passengerF.innerHTML = obj_passenger.Survived;
card.appendChild(passengerbeen);
card.appendChild(passengerF);
seccCards.appendChild(card);
}
});
};
inputFiltro.addEventListener('keyup', imprimirCards);
imprimirCards();
Aucun commentaire:
Enregistrer un commentaire