class Edificio {
constructor(celda_id, nombre){
this._celda = celda_id;
this._nombre = nombre;
}
get tipo(){
return this._tipo;
}
trazar(){
const celdas = opener.document.getElementsByClassName('celda');
for (let elm of celdas) {
if (elm.dataset.celda === this._celda) {
elm.dataset.edificio = this._nombre;
}
}
}
}
class Atraccion extends Edificio {
constructor(celda_id, nombre, visitantes){
super(celda_id, nombre);
this._visitantes = visitantes;
this._tipo = "atraccion";
}
get visitantes(){
return parseInt(this._visitantes);
}
}
class Puesto extends Edificio {
constructor(celda_id, nombre, ingresos){
super(celda_id, nombre);
this._ingresos = ingresos;
this._tipo = "puesto";
}
get ingresos(){
return parseInt(this._ingresos);
}
}
const edificios = document.getElementsByClassName('edificio');
for (let elm of edificios) {
elm.onclick = function(){
if (elm.dataset.coste <= opener.objPartida.saldo) {
const tipo = elm.dataset.tipo;
const nombre = elm.dataset.nombre;
const celda = opener.numeroCelda;
if (tipo === "atraccion") {
const visitantes = elm.dataset.visitantes;
const atraccion = new Atraccion(celda, nombre, visitantes);
atraccion.trazar();
opener.objPartida.parque.push(atraccion);
}
if (tipo === "puesto") {
const ingresos = elm.dataset.ingresos;
const puesto = new Puesto(celda, nombre, ingresos);
puesto.trazar();
opener.objPartida.parque.push(puesto);
}
opener.objPartida.saldo -= elm.dataset.coste;
opener.msg("success", "Edificio creado");
window.close();
} else {
msg('error', 'Saldo insuficiente (' + opener.objPartida.saldo + '$ restantes)');
}
}
}
I would like to make this conditional affect only two elements to change its data-edificio = vacia
attribute, its previous value being another. I do not know how to put the conditional. I want to change, for example just data-edificio = "noria"
and data-edificio = "troncos"
to data-edificio = "vacia"
.
for (let elm of celdas) {
if() //este condicional no sé cómo ponerlo
elm.dataset.edificio = "vacia";
}
Thank you.
Regards,
<div class="mapa">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div class="celda" data-edificio="vacia" data-celda="01"></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div class="celda" data-edificio="troncos" data-celda="02"></div>
<div class="celda" data-edificio="noria" data-celda="03"></div>
<div class="celda" data-edificio="auditorio" data-celda="04"></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div class="celda" data-edificio="vacia" data-celda="05"></div>
<div></div>
<div class="celda" data-edificio="vacia" data-celda="06"></div>
<div class="celda" data-edificio="vacia" data-celda="07"></div>
<div></div>
<div></div>
<div class="celda" data-edificio="vacia" data-celda="08"></div>
<div class="celda" data-edificio="vacia" data-celda="09"></div>
<div class="celda" data-edificio="vacia" data-celda="10"></div>
<div class="celda" data-edificio="vacia" data-celda="11"></div>
<div class="celda" data-edificio="vacia" data-celda="12"></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>