-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (22 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Import stylesheets
import './style.css';
// Write Javascript code!
// Array contenente gli oggetti con autore e titolo dei libri
const biblioteca = [
{ autore: "Dante Alighieri", titolo: "Divina Commedia" },
{ autore: "Alessandro Manzoni", titolo: "I Promessi Sposi" },
{ autore: "Boccaccio", titolo: "Decameron" }
];
// Sequenza di caratteri da cercare nei titoli
const stringaDaCercare = "iv";
// Filtrare i libri che corrispondono alla sequenza di caratteri
const libriCorrispondenti = biblioteca.filter(libro => libro.titolo.toLowerCase().includes(stringaDaCercare.toLowerCase()));
// Se corrisponde solo un libro, visualizzare autore e titolo, altrimenti il numero di libri corrispondenti
let contenuto;
if (libriCorrispondenti.length === 1) {
contenuto = "Autore: "+ libriCorrispondenti[0].autore + " | Titolo: " + libriCorrispondenti[0].titolo;
} else {
contenuto = "Numero di libri corrispondenti: " + libriCorrispondenti.length;
}
const appDiv = document.getElementById('app');
appDiv.innerHTML = contenuto;