Código AluGames finalizado.
Atividade 1 e 2
let quantidade = [];
function alterarStatus(id) {
let gameClicado = document.getElementById(`game-${id}`);
let imagem = gameClicado.querySelector('.dashboard__item__img');
let botao = gameClicado.querySelector('.dashboard__item__button');
if (imagem.classList.contains('dashboard__item__img--rented') && confirm('você realmente quer devolver o jogo?')) {
imagem.classList.remove('dashboard__item__img--rented');
imagem.classList.add('dashboard__item_img');
botao.classList.remove('dashboard__item__button--return');
botao.classList.add('dashboard__item__button');
botao.textContent = 'Alugar';
quantidadeAlugado(id);
} else if (confirm('Deseja alugar o jogo?')) {
imagem.classList.remove('dashboard__item_img');
imagem.classList.add('dashboard__item__img--rented');
botao.classList.add('dashboard__item__button--return');
botao.textContent = 'Devolver';
quantidadeAlugado(id);
}
}
function quantidadeAlugado(id) {
let gameClicado = document.getElementById(`game-${id}`);
let imagem = gameClicado.querySelector('.dashboard__item__img');
if (imagem.classList.contains('dashboard__item__img--rented')) {
quantidade.push(id)
console.log(`Jogos alugados: ${quantidade.length}`);
} else {
let itemRemover = id;
let indice = quantidade.indexOf(itemRemover);
if (indice !== -1) {
quantidade.splice(indice, 1);
}
console.log(`Jogos alugados: ${quantidade.length}`);
}
}
atividade 3 (palíndromo);
palíndromo()
function palíndromo() {
let palavra = prompt('digite uma palavra');
let reverso = palavra.split('').reverse().join('');
let eNumero = +reverso
let numero = isNaN(eNumero);
if (numero == true && palavra == reverso){
alert("este texto e um palíndromo");
} else if(numero == true && palavra !== reverso) {
alert('este texto não e um palíndromo');
} else if (numero == false && palavra == reverso) {
alert('este número e um palíndromo')
} else {
alert('este numero nao e um palíndromo')
}
}
Atividade 4 (Números em ordem crescente)
crescente()
function crescente() {
let numero = [1, 8, 5, 7];
numero.sort(function (a, b) {
return a - b;
});
console.log(numero);
}