<!DOCTYPE html>

<html lang="it">

<head>

   <meta charset="UTF-8">

   <meta name="viewport" content="width=device-width, initial-scale=1.0">

   <title>Calcolatore Legge di Ohm</title>

   <style>

       body {

           font-family: Arial, sans-serif;

           background-color: #f4f4f9;

           color: #333;

           margin: 0;

           padding: 0;

           display: flex;

           justify-content: center;

           align-items: center;

           height: 100vh;

       }

       .container {

           text-align: center;

           background: #fff;

           padding: 20px 30px;

           border-radius: 10px;

           box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);

           width: 90%;

           max-width: 400px;

       }

       h1 {

           margin-bottom: 20px;

           color: #0077cc;

       }

       .input-group {

           margin-bottom: 15px;

       }

       .input-group label {

           display: block;

           font-weight: bold;

           margin-bottom: 5px;

       }

       .input-group input {

           width: 100%;

           padding: 10px;

           border: 1px solid #ddd;

           border-radius: 5px;

       }

       button {

           background-color: #0077cc;

           color: #fff;

           border: none;

           padding: 10px 20px;

           font-size: 16px;

           border-radius: 5px;

           cursor: pointer;

       }

       button:hover {

           background-color: #005fa3;

       }

       .result {

           margin-top: 20px;

           padding: 10px;

           background-color: #eaf4ff;

           border-radius: 5px;

           border: 1px solid #bcdfff;

       }

   </style>

</head>

<body>

   <div class="container">

       <h1>Calcolatore Legge di Ohm</h1>

       <div class="input-group">

           <label for="voltage">Tensione (V):</label>

           <input type="number" id="voltage" placeholder="Inserisci la tensione">

       </div>

       <div class="input-group">

           <label for="current">Corrente (I):</label>

           <input type="number" id="current" placeholder="Inserisci la corrente">

       </div>

       <div class="input-group">

           <label for="resistance">Resistenza (R):</label>

           <input type="number" id="resistance" placeholder="Inserisci la resistenza">

       </div>

       <button ="calculateOhm()">Calcola</button>

       <div class="result" id="result">

           Inserisci due valori per calcolare il terzo.

       </div>

   </div>


   

       function calculateOhm() {

           const voltage = parseFloat(document.getElementById("voltage").value);

           const current = parseFloat(document.getElementById("current").value);

           const resistance = parseFloat(document.getElementById("resistance").value);

           const resultDiv = document.getElementById("result");


           if (!isNaN(voltage) && !isNaN(current)) {

               const resistanceCalc = (voltage / current).toFixed(2);

               resultDiv.textContent = `Resistenza calcolata: ${resistanceCalc} Ω`;

           } else if (!isNaN(voltage) && !isNaN(resistance)) {

               const currentCalc = (voltage / resistance).toFixed(2);

               resultDiv.textContent = `Corrente calcolata: ${currentCalc} A`;

           } else if (!isNaN(current) && !isNaN(resistance)) {

               const voltageCalc = (current * resistance).toFixed(2);

               resultDiv.textContent = `Tensione calcolata: ${voltageCalc} V`;

           } else {

               resultDiv.textContent = "Inserisci almeno due valori per calcolare il terzo.";

           }

       }

   

</body>

</html>


Carrello

    Il tuo carrello è vuoto