<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lezione 16 Febbraio</title>
<link rel="stylesheet" href="/sitewide.css"><script src="/web/dhtml/color-theme/colors.js"></script>
</head>
<body>
<div><a href="."> vai alla directory corrente. </a></div>
<div>Lezione 16 Febbraio</div>
<pre id="out"></pre>
<script>
// scrive nella pagina HTML
function puts(text) { // put string, metti stringa
window.out.innerText += text
}
function putl(line) { // put line, metti rigo
puts(line + "\n")
}
</script>
<script>
putl("ciao mondo! (scrive nella pagina)") // test di scrittura HTML, stile "hello world"
// ------------------------
const array = ["twain", "pirandello", "orwell"]
// dal termine "map", "mappa", associa elemento in ingresso con elemento in uscita
var array2 = array.map(capitalize)
putl(array2.join(", "))
// funzione che associa testo in input
// ad una uscita di testo con prima lettera maiuscola
function capitalize(text) {
return text.charAt(0).toUpperCase() + text.slice(1)
}
// ------------------------
// oggetti e mappe : associare chiave stringa con valore variabile
///for() // https://www.programiz.com/javascript/for-of
// maps, mappe chiave variabile (key/value)
var object1 = { "firstName": "Kevin", "secondName": "Goodart" }
// looping through Object, not Map
// loop attraverso un Oggetto
for (let [key, value] of Object.entries(object1)) {
putl(key + ' - ' + value);
}
//------------------------
// define Map
// definisci Mappa
let map = new Map();
// inserting elements
// inserendo elementi
map.set('bread', 0.5);
map.set('pizza', 5);
// looping through Map
// loop attraverso la Mappa
for (let [key, value] of map.entries()) {
putl(key + ' - ' + value);
}
</script>
<div><a href="."> vai alla directory corrente. </a></div>
<script src="/web/show-source.js"></script>
</body>
</html>