Prima commit
This commit is contained in:
commit
aa90e1ecf8
|
@ -0,0 +1,23 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<!-- Supporto dispositivi mobili -->
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Conversione Decimale in Binario</title>
|
||||
<link rel="stylesheet" href="res/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Convertitore Decimale in Binario</h1>
|
||||
<label for="numero">Inserisci un numero decimale (da -128 a 255):</label>
|
||||
<input type="number" id="numero" placeholder="Numero decimale" required>
|
||||
<br>
|
||||
<label for="complemento2">Usa Complemento a 2 (per numeri negativi):</label>
|
||||
<input type="checkbox" id="complemento2">
|
||||
<br>
|
||||
<button onclick="convertiBinario(document.getElementById('numero').value, document.getElementById('complemento2').checked, document.getElementById('binario'))">Converti in Binario</button>
|
||||
<h2>Risultato Binario (8 bit):</h2>
|
||||
<div id="binario">00000000</div>
|
||||
<script src="res/script.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,96 @@
|
|||
let counter = 1; // Easter egg vari
|
||||
let isDisabled = false; // Limite conversioni
|
||||
function convertiBinario(numero, isComplemento2, output) {
|
||||
// var numero = parseInt(document.getElementById('numero').value);
|
||||
// var isComplemento2 = document.getElementById('complemento2').checked;
|
||||
let binario = '';
|
||||
if (numero == 1337) { // Easter egg hacker
|
||||
alert("Hai trovato l'easter egg hacker.");
|
||||
open("https://hackertyper.net/");
|
||||
output.innerText = "HACKER";
|
||||
return;
|
||||
}
|
||||
else if (numero == 737) { // Easter egg Boeing 737
|
||||
alert("Hai trovato l'easter egg Boeing 737.");
|
||||
open("https://it.wikipedia.org/wiki/Boeing_737");
|
||||
output.innerText = "I-NEOU";
|
||||
return;
|
||||
}
|
||||
else if (numero == 380) { // Easter egg Airbus A380
|
||||
alert("Hai trovato l'easter egg Airbus A380.");
|
||||
open("https://it.wikipedia.org/wiki/Airbus_A380");
|
||||
output.innerText = "A6-EEU";
|
||||
return;
|
||||
}
|
||||
else if (numero == 787) { // Easter egg Boeing 787 Dreamliner
|
||||
alert("Hai trovato l'easter egg Boeing 787 Dreamliner.");
|
||||
open("https://it.wikipedia.org/wiki/Boeing_787_Dreamliner");
|
||||
output.innerText = "EI-NEO";
|
||||
return;
|
||||
}
|
||||
else if (numero == 747) { // Easter egg Boeing 747
|
||||
alert("Hai trovato l'easter egg Boeing 747.");
|
||||
open("https://it.wikipedia.org/wiki/Boeing_747");
|
||||
output.innerHTML = "<a href=\"https://www.theflightclub.it/2021/04/alitalia-747-baci-perugina/\" target=\"_blank\">I-DEMF</a>";
|
||||
return;
|
||||
}
|
||||
if (isDisabled) {
|
||||
return;
|
||||
}
|
||||
if (isNaN(numero) || numero < -128 || numero > 255) {
|
||||
alert("Per favore inserisci un numero valido!");
|
||||
return;
|
||||
}
|
||||
if (isComplemento2 && numero > 127) {
|
||||
alert("Per favore inserisci un numero minore/uguale a 127 o disabilita il complemento a 2!");
|
||||
}
|
||||
|
||||
if (isComplemento2) {
|
||||
|
||||
} else {
|
||||
let n = numero;
|
||||
while (n > 0) {
|
||||
binario = parseInt(binario + (n % 2));
|
||||
n = n - (n / 2);
|
||||
}
|
||||
binario = reverseString(String(binario));
|
||||
}
|
||||
output.innerText = binario;
|
||||
// Easter egg varie compagnie aeree
|
||||
if (counter == 2) {
|
||||
alert("Hai trovato l'easter egg Neos.")
|
||||
open("https://neosair.it");
|
||||
counter++;
|
||||
}
|
||||
else if (counter == 4) {
|
||||
alert("Hai trovato l'easter egg Emirates.");
|
||||
open("https://emirates.com");
|
||||
counter++;
|
||||
}
|
||||
else if (counter == 6) {
|
||||
alert("Hai trovato l'easter egg Qatar Airways.");
|
||||
open("https://qatarairways.com");
|
||||
counter++;
|
||||
}
|
||||
else if (counter == 8) {
|
||||
alert("Hai trovato l'easter egg ITA Airways.");
|
||||
open("https://ita-airways.com");
|
||||
counter++;
|
||||
}
|
||||
else if (counter == 10) {
|
||||
alert("Grazie per aver usato il convertitore. Per continuare ad usarlo, ricarica la pagina. Cliccando Ok inoltre troverai un ulteriore easter egg.");
|
||||
open("https://www.youtube.com/watch?v=b6Q1ChKJ9S4");
|
||||
isDisabled = true;
|
||||
}
|
||||
else {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
function reverseString(string){
|
||||
let Reversed = "";
|
||||
for (let i = string.length; i >= 0; i--) {
|
||||
Reversed += string[i];
|
||||
}
|
||||
return Reversed;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 20px;
|
||||
}
|
||||
input, button {
|
||||
margin: 10px 0;
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
}
|
||||
#binario {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Convertitore Base 10 a Base 2, 8, 16</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 30px;
|
||||
}
|
||||
input, button {
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
label {
|
||||
font-weight: bold;
|
||||
}
|
||||
.result {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Convertitore Base 10 a Base 2, 8, 16</h1>
|
||||
|
||||
<label for="num">Inserisci un numero in base 10:</label>
|
||||
<input type="number" id="num" required>
|
||||
|
||||
<button onclick="convert()">Converti</button>
|
||||
|
||||
<div class="result">
|
||||
<p><strong>Base 2:</strong> <span id="binaryResult"></span></p>
|
||||
<p><strong>Base 8:</strong> <span id="octalResult"></span></p>
|
||||
<p><strong>Base 16:</strong> <span id="hexResult"></span></p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function convert() {
|
||||
// Ottieni il numero in base 10 inserito
|
||||
let num = parseInt(document.getElementById("num").value);
|
||||
|
||||
// Funzione per convertire in base 2
|
||||
function toBinary(n) {
|
||||
let binary = '';
|
||||
while (n > 0) {
|
||||
binary = (n % 2) + binary;
|
||||
n = Math.floor(n / 2);
|
||||
}
|
||||
return binary === '' ? '0' : binary;
|
||||
}
|
||||
|
||||
// Funzione per convertire in base 8
|
||||
function toOctal(n) {
|
||||
let octal = '';
|
||||
while (n > 0) {
|
||||
octal = (n % 8) + octal;
|
||||
n = Math.floor(n / 8);
|
||||
}
|
||||
return octal === '' ? '0' : octal;
|
||||
}
|
||||
|
||||
// Funzione per convertire in base 16
|
||||
function toHex(n) {
|
||||
const hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
|
||||
let hex = '';
|
||||
while (n > 0) {
|
||||
hex = hexChars[n % 16] + hex;
|
||||
n = Math.floor(n / 16);
|
||||
}
|
||||
return hex === '' ? '0' : hex;
|
||||
}
|
||||
|
||||
// Esegui le conversioni
|
||||
let binaryResult = toBinary(num);
|
||||
let octalResult = toOctal(num);
|
||||
let hexResult = toHex(num);
|
||||
|
||||
// Mostra i risultati
|
||||
document.getElementById("binaryResult").textContent = binaryResult;
|
||||
document.getElementById("octalResult").textContent = octalResult;
|
||||
document.getElementById("hexResult").textContent = hexResult;
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,53 @@
|
|||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
.calculator {
|
||||
border: 2px solid #333;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
background-color: grey;
|
||||
}
|
||||
|
||||
.display {
|
||||
width: 230px;
|
||||
height: 40px;
|
||||
margin-bottom: 10px;
|
||||
text-align: right;
|
||||
font-size: 20px;
|
||||
padding: 10px;
|
||||
background-color: #f4f4f4;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.button {
|
||||
padding: 20px;
|
||||
font-size: 18px;
|
||||
background-color: #f4f4f4;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
.button:active {
|
||||
background-color: #ccc;
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--Manuel Vichi-->
|
||||
|
||||
<head>
|
||||
<title>Calculator</title>
|
||||
<link rel="stylesheet" href="calculator.css">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="calculator">
|
||||
<input type="text" class="display" id="display" disabled>
|
||||
<div class="buttons">
|
||||
<button class="button" onclick="appendToDisplay('1')">1</button>
|
||||
<button class="button" onclick="appendToDisplay('2')">2</button>
|
||||
<button class="button" onclick="appendToDisplay('3')">3</button>
|
||||
<button class="button" id="add" onclick="setOperation('+')">+</button>
|
||||
|
||||
<button class="button" onclick="appendToDisplay('4')">4</button>
|
||||
<button class="button" onclick="appendToDisplay('5')">5</button>
|
||||
<button class="button" onclick="appendToDisplay('6')">6</button>
|
||||
<button class="button" id="subtract" onclick="setOperation('-')">-</button>
|
||||
|
||||
<button class="button" onclick="appendToDisplay('7')">7</button>
|
||||
<button class="button" onclick="appendToDisplay('8')">8</button>
|
||||
<button class="button" onclick="appendToDisplay('9')">9</button>
|
||||
<button class="button" id="multiply" onclick="setOperation('*')">*</button>
|
||||
|
||||
<button class="button" onclick="appendToDisplay('0')">0</button>
|
||||
<button class="button" onclick="clearDisplay()">C</button>
|
||||
<button class="button" onclick="calculateResult()">=</button>
|
||||
<button class="button" id="divide" onclick="setOperation('/')">/</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="calculator.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,59 @@
|
|||
let currentInput = '';
|
||||
let previousInput = '';
|
||||
let operator = null;
|
||||
|
||||
function appendToDisplay(value) {
|
||||
currentInput += value;
|
||||
document.getElementById('display').value = currentInput;
|
||||
}
|
||||
|
||||
function setOperation(op) {
|
||||
if (currentInput === '') return;
|
||||
if (previousInput !== '') {
|
||||
calculateResult();
|
||||
}
|
||||
operator = op;
|
||||
previousInput = currentInput;
|
||||
currentInput = '';
|
||||
|
||||
const operationButtons = document.querySelectorAll('.button');
|
||||
operationButtons.forEach(button => button.classList.remove('active'));
|
||||
|
||||
const activeButton = document.getElementById(op);
|
||||
if (activeButton) {
|
||||
activeButton.classList.add('active');
|
||||
}
|
||||
}
|
||||
|
||||
function calculateResult() {
|
||||
if (previousInput === '' || currentInput === '') return;
|
||||
let result;
|
||||
const prev = parseFloat(previousInput);
|
||||
const current = parseFloat(currentInput);
|
||||
if (operator === '+') {
|
||||
result = prev + current;
|
||||
} else if (operator === '-') {
|
||||
result = prev - current;
|
||||
} else if (operator === '*') {
|
||||
result = prev * current;
|
||||
} else if (operator === '/') {
|
||||
if (current === 0) {
|
||||
alert("Errore: divisione per zero!");
|
||||
return;
|
||||
}
|
||||
result = prev / current;
|
||||
}
|
||||
document.getElementById('display').value = result;
|
||||
currentInput = result.toString();
|
||||
previousInput = '';
|
||||
}
|
||||
|
||||
function clearDisplay() {
|
||||
currentInput = '';
|
||||
previousInput = '';
|
||||
operator = null;
|
||||
document.getElementById('display').value = '';
|
||||
|
||||
const operationButtons = document.querySelectorAll('.button');
|
||||
operationButtons.forEach(button => button.classList.remove('active'));
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
<html>
|
||||
|
||||
<!--
|
||||
Nome: Mario
|
||||
Cognome: Montanari
|
||||
Classe: 3AIN
|
||||
-->
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="styleCalcolatricePluriOperazione.css" />
|
||||
<link rel="icon" href="itisnullobaldiniravenna.jpg" />
|
||||
<title>Calcolatrice Pluri-Operazione</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td colspan="4"><input style="width: 215px; border-radius: 10px;" type="text" id="display" disabled /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3"><button style="width: 160px; background-color: #ffd9c1; border-radius: 10px;" onclick="document.getElementById('display').value = ''; valoreDisplay = ''; risultato = 0; operatore = '';" class="bigNumber">AC</button>
|
||||
</td>
|
||||
<td><button style="background-color: #efc1ff; border-radius: 10px;" onclick="setOperator('/')" class="littleNumber">/</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('7')" class="littleNumber">7</button></td>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('8')" class="littleNumber">8</button></td>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('9')" class="littleNumber">9</button></td>
|
||||
<td><button style="background-color: #efc1ff; border-radius: 10px;" onclick="setOperator('*')" class="littleNumber">*</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('4')" class="littleNumber">4</button></td>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('5')" class="littleNumber">5</button></td>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('6')" class="littleNumber">6</button></td>
|
||||
<td><button style="background-color: #efc1ff; border-radius: 10px;" onclick="setOperator('-')" class="littleNumber">-</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('1')" class="littleNumber">1</button></td>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('2')" class="littleNumber">2</button></td>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('3')" class="littleNumber">3</button></td>
|
||||
<td><button style="background-color: #efc1ff; border-radius: 10px;" onclick="setOperator('+')" class="littleNumber">+</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><button style="background-color: #ffd9c1; border-radius: 10px;" onclick="aggiungiAlDisplay('.')" class="littleNumber">.</button></td>
|
||||
<td><button style="background-color: #c1e0ff; border-radius: 10px;" onclick="aggiungiAlDisplay('0')" class="littleNumber">0</button></td>
|
||||
<td colspan="2"><button style="width: 105px; background-color: #efc1ff; border-radius: 10px;" onclick="calcolaRisultato()" class="bigNumber">=</button></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
let valoreDisplay = ""; // Variabile che contiene il valore visualizzato sul display della calcolatrice
|
||||
let risultatoCorrente = 0; // Variabile che memorizza il risultato un'operazione alla volta (inizialmente impostato a zero)
|
||||
let operatoreCorrente = ""; // Variabile che memorizza l'operatore appena selezionato
|
||||
|
||||
// Funzione che aggiunge il valore cliccato al display della calcolatrice
|
||||
function aggiungiAlDisplay(value) {
|
||||
valoreDisplay = valoreDisplay + value; // Concatena i valore immessi nel display
|
||||
document.getElementById("display").value = valoreDisplay; // Aggiorna il valore visibile nel display della calcolatrice
|
||||
}
|
||||
|
||||
// Funzione che aggiunge l'operatore selezionato
|
||||
function setOperator(op) {
|
||||
if (valoreDisplay !== "") { // Se l'ultimo valore immesso è un numero
|
||||
calcolaRisultatoParziale(); // Funzione che calcola il risultato parziale
|
||||
operatoreCorrente = op; // Memorizza l'operatore appena selezionato
|
||||
document.getElementById("display").value = op; // Mostra l'operatore appena selezionato sul display
|
||||
valoreDisplay = ""; // Resetta il display per il prossimo numero da inserire
|
||||
} else if (valoreDisplay === "") { // Se l'ultimo valore immesso è un operatore
|
||||
resettaCalcolo();
|
||||
}
|
||||
}
|
||||
|
||||
// Funzione che calcola il risultato parziale dell'espressione che si vuole scrivere
|
||||
function calcolaRisultatoParziale() {
|
||||
if (valoreDisplay !== "") { // Se l'ultimo valore immesso è un numero
|
||||
let numeroCorrente = Number(valoreDisplay); // Converte il valore appena immesso in numero
|
||||
if (operatoreCorrente === "") { // Se l'ultimo valore immesso è un operatore
|
||||
risultatoCorrente = numeroCorrente;
|
||||
} else if (operatoreCorrente === "+") { // Se l'operatore appena immesso è il +
|
||||
document.getElementById("display").value = "+"; // Mostra l'operatore appena selezionato
|
||||
risultatoCorrente = risultatoCorrente + numeroCorrente; // Calcola la somma tra i primi due numeri immessi dell'espressione
|
||||
} else if (operatoreCorrente === "-") { // Se l'operatore appena immesso è il -
|
||||
document.getElementById("display").value = "-"; // Mostra l'operatore appena selezionato
|
||||
risultatoCorrente = risultatoCorrente - numeroCorrente; // Calcola la differenza tra i primi due numeri immessi dell'espressione
|
||||
} else if (operatoreCorrente === "*") { // Se l'operatore appena immesso è il *
|
||||
document.getElementById("display").value = "*"; // Mostra l'operatore appena selezionato
|
||||
risultatoCorrente = risultatoCorrente * numeroCorrente; // Calcola la moltiplicazione tra i primi due numeri immessi dell'espressione
|
||||
} else if (operatoreCorrente === "/") { // Se l'operatore appena immesso è il /
|
||||
if (numeroCorrente === 0) { // Se il numero appena immesso è uguale a zero
|
||||
document.getElementById("display").value = "Errore"; // Mostra nel display la scritta "Errore"
|
||||
resettaCalcolo(); // Funzione che resetta il display mostrando la scritta "Errore"
|
||||
} else { // Altrimenti
|
||||
document.getElementById("display").value = "/"; // Mostra l'operatore appena selezionato
|
||||
risultatoCorrente = risultatoCorrente / numeroCorrente; // Calcola la divisione dei primi due numeri immessi dell'espressione
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Funzione che calcola il risultato finale dell'operazione
|
||||
function calcolaRisultato() {
|
||||
if (valoreDisplay !== "") { // Se l'ultimo valore immesso è un numero
|
||||
calcolaRisultatoParziale(); // Calcola l'ultimo risultato parziale immesso dell'espressione
|
||||
document.getElementById("display").value = risultatoCorrente; // Mostra il risultato finale dell'espressione
|
||||
risultatoCorrente = 0;
|
||||
} else if (valoreDisplay === "") { // Se l'ultimo valore immesso è un operatore
|
||||
document.getElementById("display").value = "Errore";
|
||||
resettaCalcolo(); // Mostra sul display la scritta "Errore"
|
||||
}
|
||||
}
|
||||
|
||||
// Resetta i valori nel display in caso di errore
|
||||
function resettaCalcolo() {
|
||||
valoreDisplay = ""; // Resetta il valore scritto nel display
|
||||
risultatoCorrente = "Errore"; // Mostra la scritta "Errore" nel display
|
||||
operatoreCorrente = ""; // Resetta l'operatore scritto nel display
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,98 @@
|
|||
<html>
|
||||
|
||||
<!--
|
||||
Nome: Mario
|
||||
Cognome: Montanari
|
||||
Classe: 3AIN
|
||||
-->
|
||||
|
||||
<head>
|
||||
<link rel="icon" href="itisnullobaldiniravenna.jpg" />
|
||||
<link rel="stylesheet" href="styleConversioneDecimaleBinario.css" />
|
||||
<title>Conversione da decimale a binario</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Numero in Base 10:</h1>
|
||||
<input type="text" id="numeroDecimale" placeholder="Inserisci un numero decimale tra 0 e 255"/></br>
|
||||
<label for="C2">Complemento a 2</label>
|
||||
<input type="checkbox" id="C2" onchange="aggiornaPlaceholder()" /></br>
|
||||
<button onclick="conversioneBinario()">Converti in Base 2</button></br></br>
|
||||
<input id="numeroBinario" disabled />
|
||||
<script>
|
||||
|
||||
// FUNZIONE CHE CONTROLLA LO STATO DEL CHECK
|
||||
function testCheck() {
|
||||
if (document.getElementById("C2").checked) {
|
||||
document.getElementById("numeroBinario").innerHTML = "SI";
|
||||
} else {
|
||||
document.getElementById("numeroBinario").innerHTML = "NO";
|
||||
}
|
||||
}
|
||||
|
||||
// FUNZIONE CHE AGGIORNA IL PLACEHOLDER DELL'INPUT IN BASE ALLO STATO DEL CHECK
|
||||
function aggiornaPlaceholder() {
|
||||
if (document.getElementById("C2").checked) { // SE VIENE CLICCATO IL CHECKBOX
|
||||
document.getElementById("numeroDecimale").placeholder = "Inserisci un numero decimale tra -128 e 127" // IL PLACEHOLDER DELLA BARRA DI INPUT CAMBIA
|
||||
} else { // ALTRIMENTI, SE NON VIENE CLICCATO IL CHECKBOX
|
||||
document.getElementById("numeroDecimale").placeholder = "Inserisci un numero decimale tra 0 e 255"; // RIMANE IL PLACEHOLDER ORIGINALE DELLA BARRA DI INPUT
|
||||
}
|
||||
}
|
||||
|
||||
// FUNZIONE CHE CALCOLA IL NUMERO IN BASE BINARIA
|
||||
function conversioneBinario() {
|
||||
let numeroDecimale = document.getElementById("numeroDecimale").value; // INIZIALIZZAZIONE DELLA VARIBILE numeroDecimale(.value perché prende il valore da un tag <input>)
|
||||
let numeroBinario = ""; // INIZIALIZZAZIONE DELLA VARIABILE numeroBinario (stringa vuota)
|
||||
|
||||
|
||||
if (numeroDecimale !== "") { // SE VIENE IMMESSO UN NUMERO (e periò non è una stringa vuota)
|
||||
if (document.getElementById("C2").checked) { // SE IL CHECKBOX VIENE CLICCATO
|
||||
if (numeroDecimale >= -128 && numeroDecimale <= 127) { // E SE IL NUMERO IMMESSO E' COMPRESO TRA -128 E 127
|
||||
|
||||
if (numeroDecimale < "0") { // SE IL NUMERO IMMESSO E' MINORE DI 0
|
||||
numeroDecimale = 256 + Number(numeroDecimale); // AGGIUNGO 256 (2 elavato alla 8) AL VALORE DECIMALE NEGATIVO, essendo che dobbiamo rappresentare numeri binari in 8 bit
|
||||
}
|
||||
|
||||
// POI CONVERTI IL NUMERO DECIMALE IN BINARIO
|
||||
while (numeroDecimale > "0") {
|
||||
numeroBinario = (numeroDecimale % 2) + numeroBinario; // PRENDO IL RESTO DELLA DIVISIONE PER 2 DEL NUMERO DECIMALE IMMESSO (che sarà 0 o 1) E LO AGGIUNGO ALL'INIZIO DELLA STGINGA numeroBinario
|
||||
numeroDecimale = Math.floor(numeroDecimale / 2); // DIVIDO PER DUE IL NUMERO DECIMALE IMMESSO E LO ARROTONDO SEMPRE PER DIFETTO
|
||||
}
|
||||
|
||||
numeroBinario = numeroBinario.padStart(8, "0"); // RITORNO IL numeroBinario E AGGIUNGO DEGLI 0 ALLA STRINGA numeroBinario
|
||||
|
||||
} else { // ALTRIMENTI, SE IL NUMERO SFORA L'INTERVALLO -128 - 127
|
||||
window.alert("Numero non valido! Inserisci un numero compreso tra -128 e 127."); // MOSTRA UNA FINESTRA DI ALLERTA
|
||||
}
|
||||
|
||||
} else { // SE IL CHECKBOX NON VIENE CLICCATO
|
||||
if (numeroDecimale >= 0 && numeroDecimale <= 255) { // E SE IL NUMERO IMMESSO E' COMPRESO TRA 0 E 255
|
||||
|
||||
if (numeroDecimale === 0) { // SE IL NUMERO IMMESSO E' UGUALE A 0
|
||||
numeroBinario = "0"; // ALLORA RITORNA COME numeroBinario IL NUMERO 0
|
||||
} else { // ALTRIMENTI, SE IL NUMERO IMMESSO E' COMPRESO NELL'INTERVALLO 0 - 255, MA NON E' UGUALE A 0
|
||||
|
||||
// CONVERTI IL NUMERO DECIMALE NEGATIVO IN BINARIO
|
||||
while (numeroDecimale > 0) {
|
||||
numeroBinario = (numeroDecimale % 2) + numeroBinario; // PRENDO IL RESTO DELLA DIVISIONE PER 2 DEL NUMERO DECIMALE IMMESSO (che sarà 0 o 1) E LO AGGIUNGO ALL'INIZIO DELLA STGINGA numeroBinario
|
||||
numeroDecimale = Math.floor(numeroDecimale / 2); // DIVIDO PER DUE IL NUMERO DECIMALE IMMESSO E LO ARROTONDO SEMPRE PER DIFETTO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
numeroBinario = numeroBinario.padStart(8, "0"); // RITORNO IL numeroBinario E AGGIUNGO DEGLI 0 ALLA STRINGA numeroBinario
|
||||
|
||||
} else { // SE IL NUMERO IMMESSO SFORA L'INTERVALLO 0 - 255
|
||||
window.alert("Numero non valido! Inserisci un numero compreso tra 0 e 255."); // MOSTRA UNA FINESTRA DI ALLERTA
|
||||
}
|
||||
}
|
||||
} else if (numeroDecimale === "") { // ALTRIMENTI, SE NON VIENE IMMESSO NESSUN NUMERO (e periò è una stringa vuota)
|
||||
window.alert("Inserisci un numero!"); // MOSTRA UNA FINESTRA DI ALLERTA
|
||||
}
|
||||
|
||||
document.getElementById("numeroBinario").value = numeroBinario; // RITORNA IN OUTPUT IN RISULTATO DEL NUMERO BINARIO (.value perché prende il valore da un tag <input>)
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,59 @@
|
|||
<html>
|
||||
|
||||
<!--
|
||||
Nome: Mario
|
||||
Cognome: Montanari
|
||||
-->
|
||||
|
||||
<head>
|
||||
<link rel="icon" href="itisnullobaldiniravenna.jpg" />
|
||||
<link rel="stylesheet" href="styleConversioneDecimaleEsadecimale.css" />
|
||||
<title>Conversione da decimale a esidecimale</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Numero in Base 10:</h1>
|
||||
<input type="text" id="numeroDecimale" placeholder="Inserisci un numero decimale tra 0 e 255" /></br>
|
||||
<button onclick="conversioneEsadecimale()">Converti in base 16</button></br></br>
|
||||
<input id="numeroEsadecimale" disabled />
|
||||
<script>
|
||||
|
||||
function conversioneEsadecimale() {
|
||||
let numeroDecimale = document.getElementById("numeroDecimale").value;
|
||||
let numeroEsadecimale = "";
|
||||
|
||||
if (numeroDecimale !== "") {
|
||||
if (numeroDecimale >= 0 && numeroDecimale <= 255) {
|
||||
if (numeroDecimale === 0) {
|
||||
numeroEsadecimale = "0";
|
||||
}
|
||||
while (numeroDecimale > 0) {
|
||||
let restoEsadecimale = numeroDecimale % 16;
|
||||
if (restoEsadecimale === 10) {
|
||||
restoEsadecimale = "A";
|
||||
} else if (restoEsadecimale === 11) {
|
||||
restoEsadecimale = "B";
|
||||
} else if (restoEsadecimale === 12) {
|
||||
restoEsadecimale = "C";
|
||||
} else if (restoEsadecimale === 13) {
|
||||
restoEsadecimale = "D";
|
||||
} else if (restoEsadecimale === 14) {
|
||||
restoEsadecimale = "E";
|
||||
} else if (restoEsadecimale === 15) {
|
||||
restoEsadecimale = "F";
|
||||
}
|
||||
numeroEsadecimale = restoEsadecimale + numeroEsadecimale;
|
||||
numeroDecimale = Math.floor(Number(numeroDecimale) / 16);
|
||||
}
|
||||
} else {
|
||||
window.alert("Numero non valido! Inserisci un numero compreso tra 0 e 255.");
|
||||
}
|
||||
} else if (numeroDecimale === "") {
|
||||
window.alert("Inserisci un numero!");
|
||||
}
|
||||
|
||||
document.getElementById("numeroEsadecimale").value = numeroEsadecimale;
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,46 @@
|
|||
<html>
|
||||
|
||||
<!--
|
||||
Nome: Mario
|
||||
Cognome: Montanari
|
||||
Classe: 3AIN
|
||||
-->
|
||||
|
||||
<head>
|
||||
<link rel="icon" href="itisnullobaldiniravenna.jpg" />
|
||||
<link rel="stylesheet" href="styleConversioneDecimaleOttale.css" />
|
||||
<title>Conversione da decimale a ottale</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Numero in Base 10:</h1>
|
||||
<input type="text" id="numeroDecimale" placeholder="Inserisci un numero decimale tra 0 e 255" /></br>
|
||||
<button onclick="conversioneOttale()">Converti in base 8</button></br></br>
|
||||
<input id="numeroOttale" disabled />
|
||||
<script>
|
||||
|
||||
function conversioneOttale() {
|
||||
let numeroDecimale = document.getElementById("numeroDecimale").value;
|
||||
let numeroOttale = "";
|
||||
|
||||
if (numeroDecimale !== "") {
|
||||
if (numeroDecimale >= 0 && numeroDecimale <= 255) {
|
||||
if (numeroDecimale === "0") {
|
||||
numeroOttale = "0";
|
||||
}
|
||||
while (numeroDecimale > "0") {
|
||||
numeroOttale = (numeroDecimale % 8) + numeroOttale;
|
||||
numeroDecimale = Math.floor(numeroDecimale / 8);
|
||||
}
|
||||
} else {
|
||||
window.alert("Numero non valido! Inserisci un numero compreso tra 0 e 255.");
|
||||
}
|
||||
} else if (numeroDecimale === "") {
|
||||
window.alert("Inserisci un numero!");
|
||||
}
|
||||
|
||||
document.getElementById("numeroOttale").value = numeroOttale;
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,121 @@
|
|||
<html>
|
||||
|
||||
<!--
|
||||
Nome: Mario
|
||||
Cognome: Montanari
|
||||
Classe: 3AIN
|
||||
-->
|
||||
|
||||
<head>
|
||||
<link rel="icon" href="itisnullobaldiniravenna.jpg" />
|
||||
<link rel="stylesheet" href="styleConversioniConRadio.css" />
|
||||
<title>Conversioni numeriche</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Conversioni tra basi numeriche</h1>
|
||||
<input type="text" id="numeroDecimale" placeholder="Inserisci un numero decimale tra 0 e 255"/></br>
|
||||
<input type="radio" id="numeroBinario" name="tipoConversione" value="binario" />
|
||||
<label for="numeroBinario">Conversione binaria</label></br>
|
||||
<input type="radio" id="numeroOttale" name="tipoConversione" value="ottale" />
|
||||
<label for="numeroOttale">Conversione ottale</label></br>
|
||||
<input type="radio" id="numeroEsadecimale" name="tipoConversione" value="esadecimale" />
|
||||
<label for="numeroEsadecimale">Conversione esadecimale</label></br>
|
||||
<button onclick="mostraScelta()">Converti</button></br></br>
|
||||
<p id="scelta"></p>
|
||||
<script>
|
||||
function aggiornaPlaceholder() {
|
||||
if (document.getElementById("C2").checked) {
|
||||
document.getElementById("numeroDecimale").placeholder = "Inserisci un numero decimale tra -128 e 127";
|
||||
} else {
|
||||
document.getElementById("numeroDecimale").placeholder = "Inserisci un numero decimale tra 0 e 255";
|
||||
}
|
||||
}
|
||||
|
||||
function conversioneBinario() {
|
||||
let numeroDecimale = document.getElementById("numeroDecimale").value;
|
||||
let numeroBinario = "";
|
||||
if (numeroDecimale !== "") {
|
||||
if (numeroDecimale >= 0 && numeroDecimale <= 255) {
|
||||
if (numeroDecimale === 0) {
|
||||
numeroBinario = "0";
|
||||
}
|
||||
while (numeroDecimale > 0) {
|
||||
numeroBinario = (numeroDecimale % 2) + numeroBinario;
|
||||
numeroDecimale = Math.floor(numeroDecimale / 2);
|
||||
}
|
||||
} else {
|
||||
window.alert("Numero non valido! Inserisci un numero compreso tra 0 e 255.");
|
||||
}
|
||||
} else if (numeroDecimale === "") {
|
||||
window.alert("Inserisci un numero!");
|
||||
}
|
||||
return numeroBinario.padStart(8, "0");
|
||||
}
|
||||
|
||||
function conversioneOttale() {
|
||||
let numeroDecimale = document.getElementById("numeroDecimale").value;
|
||||
let numeroBinario = "";
|
||||
if (numeroDecimale !== "") {
|
||||
if (numeroDecimale >= 0 && numeroDecimale <= 255) {
|
||||
if (numeroDecimale === 0) {
|
||||
numeroBinario = "0";
|
||||
}
|
||||
while (numeroDecimale > 0) {
|
||||
numeroBinario = (numeroDecimale % 8) + numeroBinario;
|
||||
numeroDecimale = Math.floor(numeroDecimale / 8);
|
||||
}
|
||||
} else {
|
||||
window.alert("Numero non valido! Inserisci un numero compreso tra 0 e 255.");
|
||||
}
|
||||
} else if (numeroDecimale === "") {
|
||||
window.alert("Inserisci un numero!");
|
||||
}
|
||||
return numeroBinario;
|
||||
}
|
||||
|
||||
function conversioneEsadecimale() {
|
||||
let numeroDecimale = document.getElementById("numeroDecimale").value;
|
||||
let numeroEsadecimale = "";
|
||||
|
||||
if (numeroDecimale !== "") {
|
||||
if (numeroDecimale >= 0 && numeroDecimale <= 255) {
|
||||
if (numeroDecimale === 0) {
|
||||
numeroEsadecimale = "0";
|
||||
}
|
||||
while (numeroDecimale > 0) {
|
||||
let restoEsadecimale = numeroDecimale % 16;
|
||||
if (restoEsadecimale === 10) {
|
||||
restoEsadecimale = "A";
|
||||
} else if (restoEsadecimale === 11) {
|
||||
restoEsadecimale = "B";
|
||||
} else if (restoEsadecimale === 12) {
|
||||
restoEsadecimale = "C";
|
||||
} else if (restoEsadecimale === 13) {
|
||||
restoEsadecimale = "D";
|
||||
} else if (restoEsadecimale === 14) {
|
||||
restoEsadecimale = "E";
|
||||
} else if (restoEsadecimale === 15) {
|
||||
restoEsadecimale = "F";
|
||||
}
|
||||
numeroEsadecimale = restoEsadecimale + numeroEsadecimale;
|
||||
numeroDecimale = Math.floor(Number(numeroDecimale) / 16);
|
||||
}
|
||||
} else {
|
||||
window.alert("Numero non valido! Inserisci un numero compreso tra 0 e 255.");
|
||||
}
|
||||
} else if (numeroDecimale === "") {
|
||||
window.alert("Inserisci un numero!");
|
||||
}
|
||||
return numeroEsadecimale;
|
||||
}
|
||||
|
||||
function mostraScelta(){
|
||||
let scelta = "";
|
||||
if (document.getElementById('numeroBinario').checked) scelta = conversioneBinario(numeroBinario);
|
||||
if (document.getElementById('numeroOttale').checked) scelta = conversioneOttale(numeroOttale);
|
||||
if (document.getElementById('numeroEsadecimale').checked) scelta = conversioneEsadecimale(numeroEsadecimale);
|
||||
return document.getElementById("scelta").innerText = scelta;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,88 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Convertitore Base 10 a Base 2, 8, 16</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 30px;
|
||||
}
|
||||
input, button {
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
label {
|
||||
font-weight: bold;
|
||||
}
|
||||
.result {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Convertitore Base 10 a Base 2, 8, 16</h1>
|
||||
|
||||
<label for="num">Inserisci un numero in base 10:</label>
|
||||
<input type="number" id="num" required>
|
||||
|
||||
<button onclick="convert()">Converti</button>
|
||||
|
||||
<div class="result">
|
||||
<p><strong>Base 2:</strong> <span id="binaryResult"></span></p>
|
||||
<p><strong>Base 8:</strong> <span id="octalResult"></span></p>
|
||||
<p><strong>Base 16:</strong> <span id="hexResult"></span></p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function convert() {
|
||||
// Ottieni il numero in base 10 inserito
|
||||
let num = parseInt(document.getElementById("num").value);
|
||||
|
||||
// Funzione per convertire in base 2
|
||||
function toBinary(n) {
|
||||
let binary = '';
|
||||
while (n > 0) {
|
||||
binary = (n % 2) + binary;
|
||||
n = Math.floor(n / 2);
|
||||
}
|
||||
return binary === '' ? '0' : binary;
|
||||
}
|
||||
|
||||
// Funzione per convertire in base 8
|
||||
function toOctal(n) {
|
||||
let octal = '';
|
||||
while (n > 0) {
|
||||
octal = (n % 8) + octal;
|
||||
n = Math.floor(n / 8);
|
||||
}
|
||||
return octal === '' ? '0' : octal;
|
||||
}
|
||||
|
||||
// Funzione per convertire in base 16
|
||||
function toHex(n) {
|
||||
const hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
|
||||
let hex = '';
|
||||
while (n > 0) {
|
||||
hex = hexChars[n % 16] + hex;
|
||||
n = Math.floor(n / 16);
|
||||
}
|
||||
return hex === '' ? '0' : hex;
|
||||
}
|
||||
|
||||
// Esegui le conversioni
|
||||
let binaryResult = toBinary(num);
|
||||
let octalResult = toOctal(num);
|
||||
let hexResult = toHex(num);
|
||||
|
||||
// Mostra i risultati
|
||||
document.getElementById("binaryResult").textContent = binaryResult;
|
||||
document.getElementById("octalResult").textContent = octalResult;
|
||||
document.getElementById("hexResult").textContent = hexResult;
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,94 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Dec/Bin conversione</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h3>Convertitore Decimale / Binario</h3>
|
||||
|
||||
Valore decimale:<br>
|
||||
<input id="input" placeholder="Inserire valore (0 / 255)"><br>
|
||||
<br>
|
||||
|
||||
C2<br>
|
||||
<input id="checkbox" type="checkbox" onclick="checkBox()"><br>
|
||||
<br>
|
||||
|
||||
<button onclick="converti(document.getElementById('input').value)">Converti in binario</button>
|
||||
|
||||
<p id="c2visual">Non in C2:</p>
|
||||
<p id="result"></p>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
function checkBox(){
|
||||
if(document.getElementById("checkbox").checked){
|
||||
document.getElementById("c2visual").innerHTML="In C2:"
|
||||
document.getElementById("input").placeholder="Inserire valore (-127 / 127)"
|
||||
}
|
||||
else{
|
||||
document.getElementById("c2visual").innerHTML="Non in C2:"
|
||||
document.getElementById("input").placeholder="Inserire valore (0 / 255)"
|
||||
}
|
||||
}
|
||||
|
||||
function converti(n){
|
||||
let bit2 = ""
|
||||
let bit = ""
|
||||
|
||||
if(document.getElementById("checkbox").checked && n<0){
|
||||
|
||||
let segno = "0"
|
||||
if(n<0){
|
||||
segno = "1"
|
||||
n *= -1
|
||||
}
|
||||
for(let i = 0; i < 7; i++){
|
||||
if(n%2 === 0){
|
||||
bit += 1
|
||||
}
|
||||
else{
|
||||
bit += 0
|
||||
}
|
||||
if(n%2){
|
||||
n -= 1
|
||||
}
|
||||
n /=2
|
||||
}
|
||||
let inverti = bit.split('').reverse()
|
||||
|
||||
for(let j=6; j>=0; j--){
|
||||
/*if(bit[j] === 0){*/
|
||||
bit2[j] = 1
|
||||
/*break
|
||||
}*/
|
||||
}
|
||||
bit = inverti.join('');
|
||||
/*for(let j=6; j>=0; j--){
|
||||
if(bit.charAt(j) === 0){
|
||||
bit.charAt(j) = 1
|
||||
break
|
||||
}
|
||||
}*/
|
||||
document.getElementById("result").innerHTML = segno
|
||||
document.getElementById("result").innerHTML += bit
|
||||
}
|
||||
else if(!document.getElementById("checkbox").checked && n<0){
|
||||
document.getElementById("c2visual").innerHTML= "ERRORE!"
|
||||
document.getElementById("result").innerHTML = "Non è possibile convertire un numero negativo senza Complemento a 2"
|
||||
}
|
||||
else{
|
||||
for(let i = 0; i < 8; i++){
|
||||
bit += n % 2
|
||||
if(n%2){
|
||||
n -= 1
|
||||
}
|
||||
n /=2
|
||||
}
|
||||
let inverti = bit.split('').reverse().join ('');
|
||||
document.getElementById("result").innerHTML = inverti
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</html>
|
|
@ -0,0 +1,26 @@
|
|||
<html>
|
||||
<!--Patuelli Pietro-->
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<input type="radio" id="Auto" name="tipoVeicolo" value="Auto" checked>
|
||||
<label for="Auto">Auto</label><br>
|
||||
<input type="radio" id="Moto" name="tipoVeicolo" value="Moto" >
|
||||
<label for="Moto">Moto</label><br>
|
||||
<input type="radio" id="Monopattino" name="tipoVeicolo" value="Monopattino" >
|
||||
<label for="Monopattino">Monopattino</label><br>
|
||||
|
||||
<button onclick="document.getElementById('Scelta').innerHTML=mostraScelta()">CLICCAMI</button><br>
|
||||
<p id="Scelta"></p>
|
||||
<script>
|
||||
function mostraScelta(){
|
||||
/*IN QUESTO CASO DECIDO DI ACCEDERE DIRETTAMENTE ALLA PAGINA*/
|
||||
let scelta;
|
||||
if (document.getElementById('Auto').checked) scelta="HAI SCELTO AUTO";
|
||||
if (document.getElementById('Moto').checked) scelta="HAI SCELTO MOTO";
|
||||
if (document.getElementById('Monopattino').checked) scelta="HAI SCELTO MONOPATTINO";
|
||||
return scelta;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,69 @@
|
|||
<!--
|
||||
AUTORE: Manuel Vichi 3^AIN
|
||||
Esercizio 2 Stringhe: comparazione di due stringhe
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Confronto Stringhe</title>
|
||||
<style>
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
button {
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
}
|
||||
#result {
|
||||
margin-top: 20px;
|
||||
font-size: 18px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Confronto stringhe</h1>
|
||||
<textarea id="text1" placeholder="Inserisci la prima stringa"></textarea><br>
|
||||
<textarea id="text2" placeholder="Inserisci la seconda stringa"></textarea><br>
|
||||
<button onclick="confrontaStringhe()">Confronta</button>
|
||||
<div id="result"></div>
|
||||
<script>
|
||||
function confrontaStringhe() {
|
||||
const text1 = document.getElementById('text1').value;
|
||||
const text2 = document.getElementById('text2').value;
|
||||
// Conta i vari caratteri
|
||||
const count1 = contaCaratteri(text1);
|
||||
const count2 = contaCaratteri(text2);
|
||||
let risultato = true;
|
||||
// Controlla se le due stringhe hanno gli stessi caratteri
|
||||
for (let char in count1) {
|
||||
if (count1[char] !== count2[char]) {
|
||||
risultato = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Controlla se ogni carattere che è presente in count2 è anche presente in count1
|
||||
for (let char in count2) {
|
||||
if (!(char in count1)) {
|
||||
risultato = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
document.getElementById('result').innerText = risultato ? 'Le stringhe hanno la stessa distribuzione di caratteri.' : 'Le stringhe non hanno la stessa distribuzione di caratteri.';
|
||||
}
|
||||
function contaCaratteri(str) {
|
||||
// Rimuovi tutto tranne le lettere (case-insensitive)
|
||||
const cleanedStr = str.replace(/[^a-zA-Z]/g, '').toLowerCase();
|
||||
const count = {};
|
||||
// Conta la frequenza dei caratteri
|
||||
for (let char of cleanedStr) {
|
||||
count[char] = (count[char] || 0) + 1; // Se è la prima volta che il carattere viene incontrato, imposta zero. In tutti i casi infine somma 1 al valore precedentemente trovato.
|
||||
}
|
||||
return count;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,77 @@
|
|||
<!--
|
||||
AUTORE: Manuel Vichi 3^AIN
|
||||
Esercizio 1 Stringhe: conta le occorrenze dei vari caratteri e le restituisce in una tabella
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Conta Occorrenze Lettere</title>
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 25%;
|
||||
}
|
||||
table, th, td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
th, td {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Conta le Occorrenze delle Lettere</h1>
|
||||
<label for="inputString">Inserisci una stringa:</label>
|
||||
<br>
|
||||
<input type="text" id="inputString" placeholder="Scrivi qui...">
|
||||
<br>
|
||||
<button onclick="contaOccorrenze()">Conta Occorrenze</button>
|
||||
<h2>Occorrenze delle Lettere</h2>
|
||||
<table id="letterTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Lettera</th>
|
||||
<th>Occorrenze</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
function contaOccorrenze() {
|
||||
const inputString = document.getElementById('inputString').value.toLowerCase();
|
||||
const occorrenze = {};
|
||||
// Memorizza le occorrenze delle lettere in un array
|
||||
var num = 0;
|
||||
for (let char of inputString) {
|
||||
if (char >= 'a' && char <= 'z') {
|
||||
occorrenze[char] = (occorrenze[char] || 0) + 1;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
//Controlla se la stringa è vuota
|
||||
if (num == 0) {
|
||||
alert("La stringa è vuota, oppure contiene caratteri che non sono lettere.");
|
||||
return;
|
||||
}
|
||||
const tableBody = document.getElementById('letterTable').getElementsByTagName('tbody')[0]; // Ottiene le righe su cui lavorare
|
||||
tableBody.innerHTML = ''; // Inizializzazione vuota
|
||||
for (let letter = 'a'.charCodeAt(0); letter <= 'z'.charCodeAt(0); letter++) {
|
||||
const letterChar = String.fromCharCode(letter); // Controlla le occorrenze di ogni lettera dell'alfabeto
|
||||
//console.log(letterChar);
|
||||
if (occorrenze[letterChar]) {
|
||||
const row = tableBody.insertRow(); // Inserisce una riga
|
||||
// Imposta la lettera nella colonna 0 della riga
|
||||
const cellLetter = row.insertCell(0);
|
||||
cellLetter.textContent = letterChar.toUpperCase();
|
||||
// Imposta il numero di occorrenze nella colonna 1 della riga
|
||||
const cellOccorrenze = row.insertCell(1);
|
||||
cellOccorrenze.textContent = occorrenze[letterChar];
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,171 @@
|
|||
<!--
|
||||
AUTORE: Manuel Vichi 3^AIN
|
||||
Generatore di Password
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Generatore di Password</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background-color: #121212;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
color: #e0e0e0;
|
||||
/*Disabilita la selezione del body*/
|
||||
-webkit-user-select: none;
|
||||
-webkit-touch-callout: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
.container {
|
||||
background-color: #1f1f1f;
|
||||
padding: 30px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
text-align: left;
|
||||
}
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
margin-bottom: 20px;
|
||||
color: #ecf0f1;
|
||||
}
|
||||
label {
|
||||
font-size: 16px;
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
color: #bdc3c7;
|
||||
}
|
||||
input[type="checkbox"],
|
||||
button {
|
||||
margin-bottom: 15px;
|
||||
padding: 12px 15px;
|
||||
font-size: 16px;
|
||||
border: 1px solid #444;
|
||||
border-radius: 5px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
background-color: #2c3e50;
|
||||
color: #ecf0f1;
|
||||
}
|
||||
input[type="number"] {
|
||||
margin-bottom: 15px;
|
||||
padding: 12px 15px;
|
||||
font-size: 16px;
|
||||
border: 1px solid #444;
|
||||
border-radius: 5px;
|
||||
width: 20%;
|
||||
box-sizing: border-box;
|
||||
background-color: #2c3e50;
|
||||
color: #ecf0f1;
|
||||
}
|
||||
button {
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
font-weight: bold;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #2980b9;
|
||||
}
|
||||
.checkbox-container {
|
||||
text-align: left;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.checkbox-container label {
|
||||
font-size: 14px;
|
||||
color: #bdc3c7;
|
||||
}
|
||||
.checkbox-container input {
|
||||
width: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<center><h1>Generatore Password</h1></center>
|
||||
<br>
|
||||
<label for="length">Lunghezza della password: <input type="number" id="length" min="4" max="100" value="12"></label>
|
||||
<center>
|
||||
<div class="checkbox-container">
|
||||
<label for="includeNumbers">
|
||||
<input type="checkbox" id="includeNumbers"> Includi numeri
|
||||
</label><br>
|
||||
<label for="includeUppercase">
|
||||
<input type="checkbox" id="includeUppercase"> Includi lettere maiuscole
|
||||
</label><br>
|
||||
<label for="includeLowercase">
|
||||
<input type="checkbox" id="includeLowercase" checked> Includi lettere minuscole
|
||||
</label><br>
|
||||
<label for="includeSpecial">
|
||||
<input type="checkbox" id="includeSpecial"> Includi caratteri speciali
|
||||
</label>
|
||||
</div>
|
||||
<button onclick="generatePassword()">Genera Password</button>
|
||||
</center>
|
||||
<h6>Copyright © Manuel Vichi</h6>
|
||||
</div>
|
||||
<script>
|
||||
function generatePassword() {
|
||||
const length = parseInt(document.getElementById('length').value);
|
||||
const includeNumbers = document.getElementById('includeNumbers').checked;
|
||||
const includeUppercase = document.getElementById('includeUppercase').checked;
|
||||
const includeLowercase = document.getElementById('includeLowercase').checked;
|
||||
const includeSpecial = document.getElementById('includeSpecial').checked;
|
||||
// Controlla se l'utente ha selezionato almeno un tipo di caratteri
|
||||
if (!includeNumbers && !includeUppercase && !includeLowercase && !includeSpecial) {
|
||||
alert("Per il corretto funzionamento del generatore di password è necessario che almeno un tipo di caratteri sia incluso!");
|
||||
return;
|
||||
}
|
||||
// Controlla se l'utente ha chiesto una password troppo lunga (max 100 caratteri) o troppo corta (meno di 4 caratteri)
|
||||
if (length > 100) {
|
||||
alert("Per il corretto funzionamento del generatore di password la password non può essere più lunga di 100 caratteri!");
|
||||
return;
|
||||
}
|
||||
else if (length < 4) {
|
||||
alert("Per il corretto funzionamento del generatore di password la password non può essere meno lunga di 4 caratteri!");
|
||||
return;
|
||||
}
|
||||
// Dichiara la variabile contenitore dei caratteri
|
||||
var characterDatabase = '';
|
||||
// Dichiara degli insiemi di caratteri per ogni tipo
|
||||
if (includeLowercase) characterDatabase += 'abcdefghijklmnopqrstuvwxyz';
|
||||
if (includeUppercase) characterDatabase += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
if (includeNumbers) characterDatabase += '0123456789';
|
||||
if (includeSpecial) characterDatabase += '!,-.#$%^&*()_+=<>?èé[]{}§ùàòç@°|';
|
||||
// Dichiara la stringa che conterrà la password
|
||||
var password = '';
|
||||
// Costruisce la password
|
||||
for (let i = 0; i < length; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * characterDatabase.length);
|
||||
password += characterDatabase[randomIndex];
|
||||
}
|
||||
// Restituisce la password in una finestra di dialogo del browser per motivi di sicurezza
|
||||
alert(`Password generata:\n${password}\n\nNOTA: Non sarà possibile per motivi di sicurezza rivederla di nuovo, quindi salvarla in un posto sicuro.`);
|
||||
}
|
||||
// Disabilita il tasto destro
|
||||
document.oncontextmenu = document.body.oncontextmenu = function() {
|
||||
document.write("Non sei autorizzato a fare tasto destro, contatta l'amministratore del sito.");
|
||||
return false;
|
||||
}
|
||||
// Disabilita le funzioni di taglia e copia del browser
|
||||
$(document).ready(function() {
|
||||
$('body').bind('cut copy', function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,94 @@
|
|||
<html>
|
||||
|
||||
<!--
|
||||
Nome: Mario
|
||||
Cognome: Montanari
|
||||
Classe: 3AIN
|
||||
-->
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="style_addition_of_binaries.css" />
|
||||
<link rel="icon" href="itis_nullo_baldini_ravenna.jpg" />
|
||||
<title>Calcolo della Somma Binaria</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Somma tra due numeri binari</h1>
|
||||
|
||||
<p>Primo numero binario: <input type="text" id="num1" placeholder="Inserisci un numero binario" /></p>
|
||||
|
||||
<p>Secondo numero binario: <input type="text" id="num2" placeholder="Inserisci un numero binario" /></p>
|
||||
|
||||
<button onclick="sommaBin()">Calcola la Somma Binaria</button>
|
||||
|
||||
<h2>Risultato:</h2>
|
||||
<p id="sommaBin">Somma binaria: </p>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<small>Calcolo della Somma tra due numeri binari di lunghezza variabile, © 2025, Mario Montanari, 3AIN</small>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function numeriValidi(num) {
|
||||
for (let i = 0; i < num.length; i++) {
|
||||
if (num[i] !== "0" && num[i] !== "1") {
|
||||
window.alert("Numeri immessi non validi!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (num === "") {
|
||||
window.alert("Inserisci tutti i campi!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function sommaBin() {
|
||||
let num1 = document.getElementById("num1").value;
|
||||
let num2 = document.getElementById("num2").value;
|
||||
|
||||
if (!numeriValidi(num1) || !numeriValidi(num2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// let dec1 = parseInt(num1, 2);
|
||||
let bin1 = document.getElementById("num1").value;
|
||||
let dec1 = 0;
|
||||
let len1 = bin1.length;
|
||||
for (let i = 0; i < len1; i++) {
|
||||
let bit1 = parseInt(bin1[i]);
|
||||
let pot1 = len1 - i - 1;
|
||||
dec1 = dec1 + (bit1 * Math.pow(2, pot1));
|
||||
}
|
||||
|
||||
// let dec2 = parseInt(num2, 2);
|
||||
let bin2 = document.getElementById("num2").value;
|
||||
let dec2 = 0;
|
||||
let len2 = bin2.length;
|
||||
for (let i = 0; i < len2; i++) {
|
||||
let bit2 = parseInt(bin2[i]);
|
||||
let pot2 = len2 - i - 1;
|
||||
dec2 = dec2 + (bit2 * Math.pow(2, pot2));
|
||||
}
|
||||
|
||||
let sommaDec = dec1 + dec2;
|
||||
|
||||
let sommaBin = "";
|
||||
|
||||
// let sommaBin = sommaDec.toString(2);
|
||||
while (sommaDec > 0) {
|
||||
sommaBin = (sommaDec % 2) + sommaBin;
|
||||
sommaDec = Math.floor(sommaDec / 2);
|
||||
}
|
||||
|
||||
console.log(num1);
|
||||
console.log(num2);
|
||||
console.log(sommaBin);
|
||||
document.getElementById("sommaBin").innerHTML = "Somma binaria: " + sommaBin;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Verifica Bit di parità</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Verifica Bit di parità</h1>
|
||||
<input type="number" id="numero">
|
||||
<br>
|
||||
<button onclick="calcola();">Calcola</button>
|
||||
<hr>
|
||||
<h1>Risultato</h1>
|
||||
<p id="risultato">...</p>
|
||||
<script>
|
||||
function calcola() {
|
||||
let numero = document.getElementById("numero").value;
|
||||
let contatore_uni = 0;
|
||||
for (let i = 0; i < numero.length; i++) {
|
||||
if (numero[i] == 1) {
|
||||
contatore_uni++;
|
||||
}
|
||||
}
|
||||
// SOLUZIONE SEMPLICE
|
||||
if (contatore_uni == 1 || contatore_uni == 3 || contatore_uni == 5 || contatore_uni == 7) {
|
||||
document.getElementById("risultato").innerHTML = "Bit di parità: 1";
|
||||
} else {
|
||||
document.getElementById("risultato").innerHTML = "Bit di parità: 0";
|
||||
}
|
||||
// SOLUZIONE PIÙ CORRETTA
|
||||
let resto = contatore_uni % 2;
|
||||
if (resto == 1) {
|
||||
// dispari
|
||||
document.getElementById("risultato").innerHTML = "Bit di parità: 1";
|
||||
} else {
|
||||
// pari
|
||||
document.getElementById("risultato").innerHTML = "Bit di parità: 0";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,107 @@
|
|||
<html>
|
||||
|
||||
<!--
|
||||
Nome: Mario
|
||||
Cognome: Montanari
|
||||
-->
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="style_parity_code.css">
|
||||
<link rel="icon" href="itis_nullo_baldini_ravenna.jpg" />
|
||||
<title>Calcolo del Codice di Parità</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Calcolo del Codice di Parità tra due numeri binari di 8 bit</h1>
|
||||
|
||||
<p>I due numeri che inserirai qui sotto dovranno essere lunghi obbligatoriamente 8 bit.</p>
|
||||
|
||||
<p>Primo numero binario: <input type="text" id="binario1" placeholder="Inserisci un numero binario"></p>
|
||||
|
||||
<p>Secondo numero binario: <input type="text" id="binario2" placeholder="Inserisci un numero binario"></p>
|
||||
|
||||
<button onclick="calcolaParita()">Calcola il Codice di Parità</button>
|
||||
|
||||
<h2>Risultato:</h2>
|
||||
<p id="risultato">Bit di parità orizzontale per il primo numero binario:</br>Bit di parità orizzontale per il secondo numero binario</br></br>Byte di parità verticale:</br></br>Parità del primo numero binario:</br>Parità del secondo numero binario:</p>
|
||||
</div></br>
|
||||
|
||||
<div class="footer">
|
||||
<small>Calcolo del Codice di Parità tra due numeri binari obbligatoriamente di 8 bit, © 2025, Mario Montanari, 3AIN</small>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function calcolaParita() {
|
||||
let binario1 = document.getElementById('binario1').value;
|
||||
let binario2 = document.getElementById('binario2').value;
|
||||
|
||||
function isBinary(binario) {
|
||||
for (let i = 0; i < binario.length; i++) {
|
||||
if (
|
||||
binario[i] !== "0" &&
|
||||
binario[i] !== "1"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
!isBinary(binario1) ||
|
||||
!isBinary(binario2) ||
|
||||
binario1.length !== 8 ||
|
||||
binario2.length !== 8
|
||||
) {
|
||||
window.alert("Errore! Inserisci un numero binario di 8 bit.");
|
||||
return;
|
||||
}
|
||||
|
||||
function calcolaCodiceParitaRiga(binario) {
|
||||
let conteggio = 0;
|
||||
for (let i = 0; i < binario.length; i++) {
|
||||
if (binario[i] === "1") {
|
||||
conteggio++;
|
||||
}
|
||||
}
|
||||
return (conteggio % 2 === 0) ? "0" : "1";
|
||||
}
|
||||
|
||||
let paritaRiga1 = calcolaCodiceParitaRiga(binario1);
|
||||
let paritaRiga2 = calcolaCodiceParitaRiga(binario2);
|
||||
|
||||
function calcolaCodiceParitaColonna(binario1, binario2) {
|
||||
let colonnaParita = "";
|
||||
for (let i = 0; i < 8; i++) {
|
||||
let bit1 = binario1[i];
|
||||
let bit2 = binario2[i];
|
||||
let sommaBit = (bit1 === "1" ? 1 : 0) + (bit2 === "1" ? 1 : 0);
|
||||
colonnaParita = colonnaParita + (sommaBit % 2 === 0 ? "0" : "1");
|
||||
}
|
||||
return colonnaParita;
|
||||
}
|
||||
|
||||
let paritaColonne = calcolaCodiceParitaColonna(binario1, binario2);
|
||||
|
||||
let totaleBit1 = (binario1).split("").filter(bit => bit === "1").length;
|
||||
let paritaBit1 = totaleBit1 % 2 === 0 ? "Parità Pari" : "Parità Dispari";
|
||||
|
||||
let totaleBit2 = (binario2).split("").filter(bit => bit === "1").length;
|
||||
let paritaBit2 = totaleBit2 % 2 === 0 ? "Parità Pari" : "Parità Dispari";
|
||||
|
||||
console.log(binario1);
|
||||
console.log(binario2);
|
||||
console.log(paritaColonne);
|
||||
|
||||
document.getElementById("risultato").innerText =
|
||||
`Bit di parità orizzontale per il primo numero binario: ${paritaRiga1}\n` +
|
||||
`Bit di parità orizzontale per il secondo numero binario: ${paritaRiga2}\n\n` +
|
||||
`Byte di parità verticale: ${paritaColonne}\n\n` +
|
||||
`Parità del primo numero binario: ${paritaBit1}\n` +
|
||||
`Parità del secondo numero binario: ${paritaBit2}`;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,69 @@
|
|||
<!--
|
||||
AUTORE: Manuel Vichi 3^AIN
|
||||
Esercizio 2 Stringhe: comparazione di due stringhe
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Confronto Stringhe</title>
|
||||
<style>
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
button {
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
}
|
||||
#result {
|
||||
margin-top: 20px;
|
||||
font-size: 18px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Confronto stringhe</h1>
|
||||
<textarea id="text1" placeholder="Inserisci la prima stringa"></textarea><br>
|
||||
<textarea id="text2" placeholder="Inserisci la seconda stringa"></textarea><br>
|
||||
<button onclick="confrontaStringhe()">Confronta</button>
|
||||
<div id="result"></div>
|
||||
<script>
|
||||
function confrontaStringhe() {
|
||||
const text1 = document.getElementById('text1').value;
|
||||
const text2 = document.getElementById('text2').value;
|
||||
// Conta i vari caratteri
|
||||
const count1 = contaCaratteri(text1);
|
||||
const count2 = contaCaratteri(text2);
|
||||
let risultato = true;
|
||||
// Controlla se le due stringhe hanno gli stessi caratteri
|
||||
for (let char in count1) {
|
||||
if (count1[char] !== count2[char]) {
|
||||
risultato = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Controlla se ogni carattere che è presente in count2 è anche presente in count1
|
||||
for (let char in count2) {
|
||||
if (!(char in count1)) {
|
||||
risultato = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
document.getElementById('result').innerText = risultato ? 'Le stringhe hanno la stessa distribuzione di caratteri.' : 'Le stringhe non hanno la stessa distribuzione di caratteri.';
|
||||
}
|
||||
function contaCaratteri(str) {
|
||||
// Rimuovi tutto tranne le lettere (case-insensitive)
|
||||
const cleanedStr = str.replace(/[^a-zA-Z]/g, '').toLowerCase();
|
||||
const count = {};
|
||||
// Conta la frequenza dei caratteri
|
||||
for (let char of cleanedStr) {
|
||||
count[char] = (count[char] || 0) + 1; // Se è la prima volta che il carattere viene incontrato, imposta zero. In tutti i casi infine somma 1 al valore precedentemente trovato.
|
||||
}
|
||||
return count;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,77 @@
|
|||
<!--
|
||||
AUTORE: Manuel Vichi 3^AIN
|
||||
Esercizio 1 Stringhe: conta le occorrenze dei vari caratteri e le restituisce in una tabella
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Conta Occorrenze Lettere</title>
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 25%;
|
||||
}
|
||||
table, th, td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
th, td {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Conta le Occorrenze delle Lettere</h1>
|
||||
<label for="inputString">Inserisci una stringa:</label>
|
||||
<br>
|
||||
<input type="text" id="inputString" placeholder="Scrivi qui...">
|
||||
<br>
|
||||
<button onclick="contaOccorrenze()">Conta Occorrenze</button>
|
||||
<h2>Occorrenze delle Lettere</h2>
|
||||
<table id="letterTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Lettera</th>
|
||||
<th>Occorrenze</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
function contaOccorrenze() {
|
||||
const inputString = document.getElementById('inputString').value.toLowerCase();
|
||||
const occorrenze = {};
|
||||
// Memorizza le occorrenze delle lettere in un array
|
||||
var num = 0;
|
||||
for (let char of inputString) {
|
||||
if (char >= 'a' && char <= 'z') {
|
||||
occorrenze[char] = (occorrenze[char] || 0) + 1;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
//Controlla se la stringa è vuota
|
||||
if (num == 0) {
|
||||
alert("La stringa è vuota, oppure contiene caratteri che non sono lettere.");
|
||||
return;
|
||||
}
|
||||
const tableBody = document.getElementById('letterTable').getElementsByTagName('tbody')[0]; // Ottiene le righe su cui lavorare
|
||||
tableBody.innerHTML = ''; // Inizializzazione vuota
|
||||
for (let letter = 'a'.charCodeAt(0); letter <= 'z'.charCodeAt(0); letter++) {
|
||||
const letterChar = String.fromCharCode(letter); // Controlla le occorrenze di ogni lettera dell'alfabeto
|
||||
//console.log(letterChar);
|
||||
if (occorrenze[letterChar]) {
|
||||
const row = tableBody.insertRow(); // Inserisce una riga
|
||||
// Imposta la lettera nella colonna 0 della riga
|
||||
const cellLetter = row.insertCell(0);
|
||||
cellLetter.textContent = letterChar.toUpperCase();
|
||||
// Imposta il numero di occorrenze nella colonna 1 della riga
|
||||
const cellOccorrenze = row.insertCell(1);
|
||||
cellOccorrenze.textContent = occorrenze[letterChar];
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,171 @@
|
|||
<!--
|
||||
AUTORE: Manuel Vichi 3^AIN
|
||||
Generatore di Password
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Generatore di Password</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background-color: #121212;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
color: #e0e0e0;
|
||||
/*Disabilita la selezione del body*/
|
||||
-webkit-user-select: none;
|
||||
-webkit-touch-callout: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
.container {
|
||||
background-color: #1f1f1f;
|
||||
padding: 30px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
text-align: left;
|
||||
}
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
margin-bottom: 20px;
|
||||
color: #ecf0f1;
|
||||
}
|
||||
label {
|
||||
font-size: 16px;
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
color: #bdc3c7;
|
||||
}
|
||||
input[type="checkbox"],
|
||||
button {
|
||||
margin-bottom: 15px;
|
||||
padding: 12px 15px;
|
||||
font-size: 16px;
|
||||
border: 1px solid #444;
|
||||
border-radius: 5px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
background-color: #2c3e50;
|
||||
color: #ecf0f1;
|
||||
}
|
||||
input[type="number"] {
|
||||
margin-bottom: 15px;
|
||||
padding: 12px 15px;
|
||||
font-size: 16px;
|
||||
border: 1px solid #444;
|
||||
border-radius: 5px;
|
||||
width: 20%;
|
||||
box-sizing: border-box;
|
||||
background-color: #2c3e50;
|
||||
color: #ecf0f1;
|
||||
}
|
||||
button {
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
font-weight: bold;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #2980b9;
|
||||
}
|
||||
.checkbox-container {
|
||||
text-align: left;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.checkbox-container label {
|
||||
font-size: 14px;
|
||||
color: #bdc3c7;
|
||||
}
|
||||
.checkbox-container input {
|
||||
width: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<center><h1>Generatore Password</h1></center>
|
||||
<br>
|
||||
<label for="length">Lunghezza della password: <input type="number" id="length" min="4" max="100" value="12"></label>
|
||||
<center>
|
||||
<div class="checkbox-container">
|
||||
<label for="includeNumbers">
|
||||
<input type="checkbox" id="includeNumbers"> Includi numeri
|
||||
</label><br>
|
||||
<label for="includeUppercase">
|
||||
<input type="checkbox" id="includeUppercase"> Includi lettere maiuscole
|
||||
</label><br>
|
||||
<label for="includeLowercase">
|
||||
<input type="checkbox" id="includeLowercase" checked> Includi lettere minuscole
|
||||
</label><br>
|
||||
<label for="includeSpecial">
|
||||
<input type="checkbox" id="includeSpecial"> Includi caratteri speciali
|
||||
</label>
|
||||
</div>
|
||||
<button onclick="generatePassword()">Genera Password</button>
|
||||
</center>
|
||||
<h6>Copyright © Manuel Vichi</h6>
|
||||
</div>
|
||||
<script>
|
||||
function generatePassword() {
|
||||
const length = parseInt(document.getElementById('length').value);
|
||||
const includeNumbers = document.getElementById('includeNumbers').checked;
|
||||
const includeUppercase = document.getElementById('includeUppercase').checked;
|
||||
const includeLowercase = document.getElementById('includeLowercase').checked;
|
||||
const includeSpecial = document.getElementById('includeSpecial').checked;
|
||||
// Controlla se l'utente ha selezionato almeno un tipo di caratteri
|
||||
if (!includeNumbers && !includeUppercase && !includeLowercase && !includeSpecial) {
|
||||
alert("Per il corretto funzionamento del generatore di password è necessario che almeno un tipo di caratteri sia incluso!");
|
||||
return;
|
||||
}
|
||||
// Controlla se l'utente ha chiesto una password troppo lunga (max 100 caratteri) o troppo corta (meno di 4 caratteri)
|
||||
if (length > 100) {
|
||||
alert("Per il corretto funzionamento del generatore di password la password non può essere più lunga di 100 caratteri!");
|
||||
return;
|
||||
}
|
||||
else if (length < 4) {
|
||||
alert("Per il corretto funzionamento del generatore di password la password non può essere meno lunga di 4 caratteri!");
|
||||
return;
|
||||
}
|
||||
// Dichiara la variabile contenitore dei caratteri
|
||||
var characterDatabase = '';
|
||||
// Dichiara degli insiemi di caratteri per ogni tipo
|
||||
if (includeLowercase) characterDatabase += 'abcdefghijklmnopqrstuvwxyz';
|
||||
if (includeUppercase) characterDatabase += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
if (includeNumbers) characterDatabase += '0123456789';
|
||||
if (includeSpecial) characterDatabase += '!,-.#$%^&*()_+=<>?èé[]{}§ùàòç@°|';
|
||||
// Dichiara la stringa che conterrà la password
|
||||
var password = '';
|
||||
// Costruisce la password
|
||||
for (let i = 0; i < length; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * characterDatabase.length);
|
||||
password += characterDatabase[randomIndex];
|
||||
}
|
||||
// Restituisce la password in una finestra di dialogo del browser per motivi di sicurezza
|
||||
alert(`Password generata:\n${password}\n\nNOTA: Non sarà possibile per motivi di sicurezza rivederla di nuovo, quindi salvarla in un posto sicuro.`);
|
||||
}
|
||||
// Disabilita il tasto destro
|
||||
document.oncontextmenu = document.body.oncontextmenu = function() {
|
||||
document.write("Non sei autorizzato a fare tasto destro, contatta l'amministratore del sito.");
|
||||
return false;
|
||||
}
|
||||
// Disabilita le funzioni di taglia e copia del browser
|
||||
$(document).ready(function() {
|
||||
$('body').bind('cut copy', function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,96 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Trova la parola più lunga in una frase</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #f4f6f8;
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 40px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
-webkit-user-select: none;
|
||||
-webkit-touch-callout: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #2c3e50;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
max-width: 700px;
|
||||
height: 120px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 8px;
|
||||
resize: vertical;
|
||||
font-size: 16px;
|
||||
box-shadow: 2px 2px 10px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
button {
|
||||
margin-top: 20px;
|
||||
padding: 12px 24px;
|
||||
font-size: 16px;
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #2980b9;
|
||||
}
|
||||
|
||||
.result, .occurrence {
|
||||
margin-top: 30px;
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
||||
width: 100%;
|
||||
max-width: 700px;
|
||||
}
|
||||
|
||||
.occurrence ul {
|
||||
padding-left: 20px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.occurrence li {
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
body {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
textarea, .result, .occurrence {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Trova la parola più lunga in una frase</h1>
|
||||
<textarea id="textInput" placeholder="Inserisci una frase..."></textarea><br>
|
||||
<button onclick="esercizio1()">Analizza</button>
|
||||
|
||||
<div class="result"><strong id="longestWordResult"></strong></div>
|
||||
<div class="occurrence" id="wordOccurrences"></div>
|
||||
|
||||
<script src="esercizi.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,95 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Ordinatore di Numeri</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Segoe UI', sans-serif;
|
||||
background: linear-gradient(135deg, #f9f9f9, #e0f7fa);
|
||||
margin: 0;
|
||||
padding: 40px 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
-webkit-user-select: none;
|
||||
-webkit-touch-callout: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #2c3e50;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
height: 120px;
|
||||
padding: 15px;
|
||||
font-size: 16px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #ccc;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
||||
resize: vertical;
|
||||
background-color: #ffffff;
|
||||
transition: border 0.3s ease;
|
||||
}
|
||||
|
||||
textarea:focus {
|
||||
border-color: #00bcd4;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button {
|
||||
margin-top: 20px;
|
||||
padding: 12px 30px;
|
||||
font-size: 16px;
|
||||
background-color: #00bcd4;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 4px 10px rgba(0, 188, 212, 0.2);
|
||||
transition: background-color 0.3s, transform 0.2s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #0097a7;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
#output {
|
||||
margin-top: 30px;
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
background-color: #ffffff;
|
||||
padding: 20px;
|
||||
border-radius: 12px;
|
||||
max-width: 600px;
|
||||
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.08);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
textarea, #output {
|
||||
width: 90%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Ordina Numeri Reali</h1>
|
||||
<textarea id="numberInput" placeholder="Inserisci numeri separati da ;"></textarea><br>
|
||||
<button onclick="esercizio2()">Ordina</button>
|
||||
|
||||
<p id="output"></p>
|
||||
|
||||
<script src="esercizi.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,90 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Generatore di Acronimi</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
background: #f0f4f8;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
-webkit-user-select: none;
|
||||
-webkit-touch-callout: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: #ffffff;
|
||||
padding: 30px 40px;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
|
||||
max-width: 600px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
padding: 10px;
|
||||
border: 2px solid #dce3ea;
|
||||
border-radius: 10px;
|
||||
resize: none;
|
||||
font-size: 16px;
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #4f9da6;
|
||||
color: white;
|
||||
padding: 12px 20px;
|
||||
margin-top: 20px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
transition: background-color 0.3s ease;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #3d7f86;
|
||||
}
|
||||
|
||||
#acronym {
|
||||
margin-top: 20px;
|
||||
font-size: 1.5em;
|
||||
font-weight: 600;
|
||||
color: #2e5e68;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Generatore di Acronimi</h1>
|
||||
<textarea id="inputText" placeholder="Es: Self Contained Underwater Breathing Apparatus"></textarea>
|
||||
<button onclick="esercizio3()">Genera Acronimo</button>
|
||||
<div id="acronym"></div>
|
||||
</div>
|
||||
|
||||
<script src="esercizi.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,104 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Verifica Palindromo</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
background: linear-gradient(135deg, #c3ecf5, #e2d1f9);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
-webkit-user-select: none;
|
||||
-webkit-touch-callout: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
backdrop-filter: blur(10px);
|
||||
padding: 40px 30px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.1);
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
border-radius: 10px;
|
||||
border: 2px solid #ccc;
|
||||
padding: 12px;
|
||||
font-size: 16px;
|
||||
resize: none;
|
||||
transition: border-color 0.3s ease;
|
||||
}
|
||||
|
||||
textarea:focus {
|
||||
border-color: #7a5cf0;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button {
|
||||
margin-top: 20px;
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background-color: #7a5cf0;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #6547d1;
|
||||
}
|
||||
|
||||
#risultato {
|
||||
margin-top: 25px;
|
||||
font-size: 1.2em;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.positivo {
|
||||
color: #28a745;
|
||||
}
|
||||
|
||||
.negativo {
|
||||
color: #dc3545;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Verifica se una frase è palindroma</h1>
|
||||
<textarea id="inputFrase" placeholder="Es: I topi non avevano nipoti"></textarea>
|
||||
<button onclick="esercizioOmaggio()">Verifica</button>
|
||||
<div id="risultato"></div>
|
||||
</div>
|
||||
<script src="esercizi.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,152 @@
|
|||
function esercizio1() {
|
||||
const text = document.getElementById("textInput").value;
|
||||
const words = text
|
||||
.toLowerCase()
|
||||
.replace(/[^\w\sàèéìòù]/g, '')
|
||||
.split(/\s+/)
|
||||
.filter(word => word.length > 0);
|
||||
if (words.length === 0) {
|
||||
document.getElementById("longestWordResult").textContent = "Nessuna parola trovata.";
|
||||
document.getElementById("wordOccurrences").textContent = "";
|
||||
return;
|
||||
}
|
||||
let longestWord = words.reduce((a, b) => (b.length > a.length ? b : a));
|
||||
const occurrences = {};
|
||||
for (let word of words) {
|
||||
occurrences[word] = (occurrences[word] || 0) + 1;
|
||||
}
|
||||
document.getElementById("longestWordResult").textContent =
|
||||
"🔍 Parola più lunga: " + longestWord;
|
||||
|
||||
let occHTML = "<h3>📊 Occorrenze delle parole:</h3><ul>";
|
||||
for (let word in occurrences) {
|
||||
occHTML += `<li><strong>${word}</strong>: ${occurrences[word]}</li>`;
|
||||
}
|
||||
occHTML += "</ul>";
|
||||
document.getElementById("wordOccurrences").innerHTML = occHTML;
|
||||
}
|
||||
function esercizio2() {
|
||||
const input = document.getElementById('numberInput').value;
|
||||
const numeri = input
|
||||
.split(';')
|
||||
.map(n => parseFloat(n.trim()))
|
||||
.filter(n => !isNaN(n));
|
||||
const output = document.getElementById('output');
|
||||
if (numeri.length === 0) {
|
||||
output.textContent = "⚠️ Nessun numero valido inserito.";
|
||||
return;
|
||||
}
|
||||
numeri.sort((a, b) => a - b);
|
||||
output.textContent = "✅ Numeri ordinati: " + numeri.join(', ');
|
||||
}
|
||||
function esercizio3() {
|
||||
const testo = document.getElementById("inputText").value;
|
||||
const parole = testo.trim().split(/\s+/);
|
||||
let acronimo = "";
|
||||
|
||||
for (let parola of parole) {
|
||||
if (parola.length > 0) {
|
||||
acronimo += parola[0].toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("acronym").textContent = acronimo ? "Acronimo: " + acronimo : "";
|
||||
}
|
||||
function isPalindroma(frase) {
|
||||
const pulita = frase.toLowerCase().replace(/[^a-z0-9]/gi, '');
|
||||
const invertita = pulita.split('').reverse().join('');
|
||||
return pulita === invertita;
|
||||
}
|
||||
|
||||
function esercizioOmaggio() {
|
||||
const input = document.getElementById('inputFrase').value.trim();
|
||||
const risultatoDiv = document.getElementById('risultato');
|
||||
|
||||
if (!input) {
|
||||
risultatoDiv.textContent = "⚠️ Inserisci una frase!";
|
||||
risultatoDiv.className = 'negativo';
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPalindroma(input)) {
|
||||
risultatoDiv.textContent = "✅ La frase è palindroma!";
|
||||
risultatoDiv.className = 'positivo';
|
||||
} else {
|
||||
risultatoDiv.textContent = "❌ La frase NON è palindroma.";
|
||||
risultatoDiv.className = 'negativo';
|
||||
}
|
||||
}
|
||||
|
||||
//Funzioni per prevenire la copia
|
||||
document.oncontextmenu = document.body.oncontextmenu = function() {
|
||||
document.write(`
|
||||
Right click is not allowed on this site! Reload page!
|
||||
`);
|
||||
return false;
|
||||
};
|
||||
function devToolsOpened(e){
|
||||
e.preventDefault();
|
||||
}
|
||||
window.addEventListener('keydown', function(e) {
|
||||
if (
|
||||
e.metaKey == true && e.altKey == true && e.keyCode == 73 ||
|
||||
e.metaKey == true && e.altKey == true && e.keyCode == 74 ||
|
||||
e.metaKey == true && e.altKey == true && e.keyCode == 67 ||
|
||||
e.metaKey == true && e.shiftKey == true && e.keyCode == 67 ||
|
||||
e.ctrlKey == true && e.shiftKey == true && e.keyCode == 73 ||
|
||||
e.ctrlKey == true && e.shiftKey == true && e.keyCode == 74 ||
|
||||
e.ctrlKey == true && e.shiftKey == true && e.keyCode == 67 ||
|
||||
e.keyCode == 123 ||
|
||||
e.metaKey == true && e.altKey == true && e.keyCode == 85 ||
|
||||
e.ctrlKey == true && e.keyCode == 85 ||
|
||||
e.ctrlKey == true && e.keyCode == 80
|
||||
){
|
||||
devToolsOpened(e);
|
||||
}
|
||||
});
|
||||
const devtools = {
|
||||
isOpen: false,
|
||||
orientation: undefined,
|
||||
};
|
||||
|
||||
const threshold = 170;
|
||||
|
||||
const emitEvent = (isOpen, orientation) => {
|
||||
globalThis.dispatchEvent(new globalThis.CustomEvent('devtoolschange', {
|
||||
detail: {
|
||||
isOpen,
|
||||
orientation,
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
const main = ({emitEvents = true} = {}) => {
|
||||
const widthThreshold = globalThis.outerWidth - globalThis.innerWidth > threshold;
|
||||
const heightThreshold = globalThis.outerHeight - globalThis.innerHeight > threshold;
|
||||
const orientation = widthThreshold ? 'vertical' : 'horizontal';
|
||||
|
||||
if (
|
||||
!(heightThreshold && widthThreshold)
|
||||
&& ((globalThis.Firebug && globalThis.Firebug.chrome && globalThis.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)
|
||||
) {
|
||||
if ((!devtools.isOpen || devtools.orientation !== orientation) && emitEvents) {
|
||||
emitEvent(true, orientation);
|
||||
}
|
||||
|
||||
devtools.isOpen = true;
|
||||
devtools.orientation = orientation;
|
||||
} else {
|
||||
if (devtools.isOpen && emitEvents) {
|
||||
emitEvent(false, undefined);
|
||||
}
|
||||
|
||||
devtools.isOpen = false;
|
||||
devtools.orientation = undefined;
|
||||
}
|
||||
};
|
||||
setInterval(main, 500);
|
||||
window.addEventListener('devtoolschange', event => {
|
||||
document.write(`
|
||||
Please close DevTools, then reload the page!
|
||||
`);
|
||||
});
|
|
@ -0,0 +1,106 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Esercizi TPS Vichi per 2025-04-26</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Nunito', sans-serif;
|
||||
background: linear-gradient(135deg, #d2e1f0, #f9e9ff);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
-webkit-user-select: none;
|
||||
-webkit-touch-callout: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 900px;
|
||||
padding: 40px;
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 32px;
|
||||
color: #333;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: #f2f5fa;
|
||||
padding: 20px;
|
||||
border-radius: 15px;
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.05);
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-5px);
|
||||
background-color: #e4ecf7;
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
font-size: 20px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.card p {
|
||||
font-size: 14px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
footer {
|
||||
margin-top: 30px;
|
||||
font-size: 14px;
|
||||
color: #888;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>💡 Esercizi TPS Vichi per 2025-04-26</h1>
|
||||
<div class="grid">
|
||||
<a href="Esercizio1.html" class="card" target="_blank">
|
||||
<h2>🧩 Esercizio 1</h2>
|
||||
<p>Trova la parola più lunga in una frase.</p>
|
||||
</a>
|
||||
<a href="Esercizio2.html" class="card" target="_blank">
|
||||
<h2>🧩 Esercizio 2</h2>
|
||||
<p>Ordina i numeri</p>
|
||||
</a>
|
||||
<a href="Esercizio3.html" class="card" target="_blank">
|
||||
<h2>🧩 Esercizio 3</h2>
|
||||
<p>Generatore di acronimi</p>
|
||||
</a>
|
||||
<a href="EsercizioOmaggio.html" class="card" target="_blank">
|
||||
<h2>🧩 Esercizio Omaggio</h2>
|
||||
<p>Verifica se una frase è palindroma.</p>
|
||||
</a>
|
||||
</div>
|
||||
<footer>
|
||||
Creato da Manuel Vichi
|
||||
</footer>
|
||||
</div>
|
||||
<script src="esercizi.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Lancio dei Dadi</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
}
|
||||
input, button {
|
||||
padding: 8px;
|
||||
font-size: 16px;
|
||||
margin: 5px 0;
|
||||
}
|
||||
.results {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>Simulatore Lancio Dadi</h2>
|
||||
|
||||
<label for="numDadi">Numero di dadi:</label><br>
|
||||
<input type="number" id="numDadi" min="1" value="5"><br>
|
||||
|
||||
<label for="numFacce">Numero di facce per dado:</label><br>
|
||||
<input type="number" id="numFacce" min="2" value="6"><br>
|
||||
|
||||
<button onclick="esercizio2()">Lancia!</button>
|
||||
|
||||
<div class="results" id="results"></div>
|
||||
|
||||
<script src="esercizi.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Cambia Colore Testo</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
}
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
font-size: 16px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
select, button {
|
||||
padding: 8px;
|
||||
font-size: 16px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>Cambia il colore del testo</h2>
|
||||
|
||||
<textarea id="textArea" placeholder="Scrivi qui il tuo testo..."></textarea><br>
|
||||
|
||||
<select id="colorSelect">
|
||||
<option value="black">Nero</option>
|
||||
<option value="red">Rosso</option>
|
||||
<option value="blue">Blu</option>
|
||||
<option value="green">Verde</option>
|
||||
<option value="purple">Viola</option>
|
||||
<option value="orange">Arancione</option>
|
||||
<option value="yellow">Giallo</option>
|
||||
</select>
|
||||
|
||||
<button onclick="esercizio1()">Applica Colore</button>
|
||||
<script src="esercizi.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,36 @@
|
|||
function esercizio1() {
|
||||
const textarea = document.getElementById('textArea');
|
||||
const coloreSelezionato = document.getElementById('colorSelect').value;
|
||||
textarea.style.color = coloreSelezionato;
|
||||
}
|
||||
function esercizio2() {
|
||||
const numDadi = parseInt(document.getElementById('numDadi').value);
|
||||
const numFacce = parseInt(document.getElementById('numFacce').value);
|
||||
const risultati = [];
|
||||
for (let i = 0; i < numDadi; i++) {
|
||||
const risultato = Math.floor(Math.random() * numFacce) + 1;
|
||||
risultati.push(risultato);
|
||||
}
|
||||
const somma = risultati.reduce((acc, val) => acc + val, 0);
|
||||
const media = somma / risultati.length;
|
||||
const conteggi = {};
|
||||
risultati.forEach(val => {
|
||||
conteggi[val] = (conteggi[val] || 0) + 1;
|
||||
});
|
||||
|
||||
let moda = risultati[0];
|
||||
let maxContatore = conteggi[moda];
|
||||
|
||||
for (const numero in conteggi) {
|
||||
if (conteggi[numero] > maxContatore) {
|
||||
moda = numero;
|
||||
maxContatore = conteggi[numero];
|
||||
}
|
||||
}
|
||||
const resultsDiv = document.getElementById('results');
|
||||
resultsDiv.innerHTML = `
|
||||
<strong>Risultati:</strong> ${risultati.join(', ')}<br>
|
||||
<strong>Media:</strong> ${media.toFixed(2)}<br>
|
||||
<strong>Moda:</strong> ${moda}
|
||||
`;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Pagina</title>
|
||||
</head>
|
||||
</html>
|
|
@ -0,0 +1,76 @@
|
|||
<!-- Manuel Vichi 3^AIN - Esercizio 1 -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Generatore Bit di Parita'</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 30px;
|
||||
}
|
||||
input, button {
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
label {
|
||||
font-weight: bold;
|
||||
}
|
||||
.result {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Generatore bit di parita'</h1>
|
||||
|
||||
<label for="num">Inserisci un numero in base 2 (in 7 bit):</label>
|
||||
<input type="number" id="num" required>
|
||||
<br><br>
|
||||
<label for="paritypeer">Parita' pari</label>
|
||||
<input type="radio" id="paritypeer" name="parity" value="paritypeer" checked>
|
||||
<br>
|
||||
<label for="paritypeer">Parita' dispari</label>
|
||||
<input type="radio" id="paritynotpeer" name="parity" value="paritynotpeer">
|
||||
<br><br>
|
||||
<button onclick="generate()">Genera</button>
|
||||
|
||||
<div class="result">
|
||||
<p><strong>Risultato parita':</strong> <span id="parityResult"></span></p>
|
||||
</div>
|
||||
<script>
|
||||
function generate() {
|
||||
let original = String(document.getElementById("num").value);
|
||||
for (let i = 0; i < original.length; i++) {
|
||||
if (original[i] != "0" && original[i] != "1") {
|
||||
alert("Il numero deve essere binario!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
let num = parseInt(original);
|
||||
if (original.length != 7) {
|
||||
alert("Il numero deve essere su 7 bit!");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
let unProcioneInCalore = 0;
|
||||
for (let i = 0; i < original.length; i++) {
|
||||
if (original[i] == "0") {
|
||||
unProcioneInCalore++;
|
||||
}
|
||||
}
|
||||
if (document.getElementById('paritypeer').checked && unProcioneInCalore % 2 == 0) {
|
||||
document.getElementById('parityResult').textContent = original + " 1";
|
||||
}
|
||||
else if (document.getElementById('paritynotpeer').checked && unProcioneInCalore % 2 != 0) {
|
||||
document.getElementById('parityResult').textContent = original + " 1";
|
||||
}
|
||||
else {
|
||||
document.getElementById('parityResult').textContent = original + " 0";
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,61 @@
|
|||
<!-- Manuel Vichi 3^AIN - Esercizio 2 -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Convertitore Base 10 a Base 16</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 30px;
|
||||
}
|
||||
input, button {
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
label {
|
||||
font-weight: bold;
|
||||
}
|
||||
.result {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Convertitore Base 10 a base 16</h1>
|
||||
|
||||
<label for="num">Inserisci un numero in base 10:</label>
|
||||
<input type="number" id="num" required>
|
||||
<p>In caso di numero decimale esso viene automaticamente arrotondato.</p>
|
||||
|
||||
<button onclick="converti()">Converti</button>
|
||||
|
||||
<div class="result">
|
||||
<p><strong>Base 16:</strong> <span id="hexResult"></span></p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function converti() {
|
||||
let original = document.getElementById("num").value;
|
||||
let num = parseInt(original);
|
||||
if (num < 0) {
|
||||
alert("Il numero deve essere positivo!");
|
||||
return;
|
||||
}
|
||||
function esadec(n) {
|
||||
const hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
|
||||
let hex = '';
|
||||
while (n > 0) {
|
||||
hex = hexChars[n % 16] + hex;
|
||||
n = parseInt(n / 16);
|
||||
}
|
||||
return hex === '' ? '0' : hex;
|
||||
}
|
||||
let hexResult = esadec(num);
|
||||
document.getElementById("hexResult").textContent = hexResult;
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue