Find the missing DC quantity
HTML for this example
Select the code and use your copy shortcut. Changes in this preview are temporary.
<!doctype html>
<html lang="en-US"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Find the missing DC quantity</title><style>*{box-sizing:border-box}body{margin:0;background:#f3f4f2;color:#202c32;font:16px/1.5 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}main{max-width:1120px;margin:auto;padding:30px 28px 60px}header{margin-bottom:22px}.eyebrow{font-size:12px;letter-spacing:.14em;text-transform:uppercase;font-weight:750;color:#59676b}h1{font-size:clamp(25px,4vw,36px);line-height:1.15;letter-spacing:-.035em;margin:7px 0 10px}h2{font-size:21px;line-height:1.3;margin:0 0 16px}h3{font-size:17px;margin:0 0 10px}p{margin:8px 0 16px}label{display:block;font-size:14px;font-weight:650;margin:12px 0 5px}input,select,textarea,button{font:inherit}input,select,textarea{width:100%;min-width:0;border:1px solid #b6c0bf;border-radius:7px;background:#fff;color:#202c32;padding:10px 12px}textarea{resize:vertical;min-height:88px}input[type=checkbox]{width:18px;height:18px;vertical-align:middle;margin-right:8px}button{border:1px solid #b8c3c1;border-radius:7px;padding:10px 15px;background:#fff;color:#203632;font-weight:650;cursor:pointer}button.primary{background:#243f3c;color:white;border-color:#243f3c}button:hover{filter:brightness(.95)}button:disabled{opacity:.48;cursor:not-allowed}:focus-visible{outline:3px solid #b05814;outline-offset:3px}.buttons{display:flex;gap:8px;flex-wrap:wrap;margin-top:18px}.panel{background:#fff;border:1px solid #d7ddda;border-radius:12px;padding:24px}.split{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.1fr);gap:22px}.row{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}.result{background:#e4eee8;border:1px solid #c5d6ca;border-radius:12px;padding:28px}.big{font-size:clamp(32px,5vw,56px);font-weight:740;line-height:1.14;letter-spacing:-.04em;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}.muted{color:#59686a;font-size:14px}.tag{display:inline-block;background:#edf0ed;border-radius:4px;padding:3px 8px;font-size:12px;font-weight:700}.error{color:#9d301b;font-weight:650;min-height:24px;margin-top:10px}.note{border-left:3px solid #9a794a;padding:10px 15px;background:#faf5e9;margin:18px 0}.below{margin-top:28px}.record{white-space:pre-wrap;overflow-wrap:anywhere;font:14px/1.65 ui-monospace,SFMono-Regular,Consolas,monospace;background:#f2f4f1;padding:18px;border-radius:8px}table{width:100%;border-collapse:collapse;font-size:14px}th,td{text-align:left;vertical-align:top;border-bottom:1px solid #dce1dd;padding:12px 10px;overflow-wrap:anywhere}th{color:#59686a;font-size:12px}a{color:#2c5a6a;overflow-wrap:anywhere}details{margin-top:20px}summary{cursor:pointer;font-weight:650}hr{border:0;border-top:1px solid #d6dcd6;margin:22px 0}[hidden]{display:none!important}ol,ul{padding-left:23px}.statline{display:flex;gap:20px;flex-wrap:wrap;margin:18px 0}.statline strong{display:block;font-size:24px}.inline{display:flex;align-items:center;gap:8px}.inline label{margin:0} .blank{min-height:36px;border-bottom:1px dashed #aebbb5;color:#66736d;font-size:13px;padding:8px 0}@media(max-width:720px){main{padding:22px 18px 45px}.split{grid-template-columns:1fr}.panel,.result{padding:20px}.row{gap:12px}th,td{padding:10px 6px}}@media(max-width:400px){main{padding:18px 14px 40px}.big{font-size:34px}button{padding:10px 12px}.row{grid-template-columns:1fr}.panel,.result{padding:17px}}.inline{flex-wrap:wrap}input[type=range]{padding:0}pre{white-space:pre-wrap;overflow-wrap:anywhere;margin:0}.metric{font-size:42px;font-weight:750;line-height:1.15;letter-spacing:-.035em}.caption{font-size:13px;color:#55656b}.readout{font:15px/1.6 ui-monospace,Consolas,monospace;white-space:pre-wrap;overflow-wrap:anywhere}.strip{display:flex;gap:24px;align-items:center;flex-wrap:wrap}.chip{padding:5px 10px;background:#e5eaf0;border-radius:5px;font-size:13px}button[aria-pressed=true]{background:#263b50;color:white}.subtle{background:#f6f7f7}.fileCode{min-height:230px;font:14px/1.6 ui-monospace,Consolas,monospace}.wideButton{width:100%}.visuallyHidden{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}svg{max-width:100%}.nowrap{white-space:nowrap}.electrical{display:grid;grid-template-columns:1fr 1fr;gap:24px}.electrical .result{background:#f2e8ce;border-color:#ddcea6;display:flex;flex-direction:column;justify-content:center}.equations{display:grid;grid-template-columns:repeat(3,1fr);gap:20px;margin-bottom:24px}.equations strong{font:700 23px ui-monospace,Consolas,monospace}.equations p{font-size:14px;margin-top:7px}@media(max-width:720px){.electrical{grid-template-columns:1fr}.equations{grid-template-columns:1fr;gap:10px}}</style></head><body><main><header><div class="eyebrow">Power · Current · Voltage</div><h1>Find the missing DC quantity</h1></header>
<section class="electrical"><div class="result"><span class="eyebrow" id="unknownLabel">Calculated power</span><div id="answer" class="big">24 W</div><p id="equation">P = 12 V × 2 A = 24 W</p><span class="chip">Steady DC · Nonnegative scalar magnitudes</span></div><form class="panel" id="form" novalidate><label for="mode">Find the unknown</label><select id="mode"><option value="">Choose the unknown</option><option value="W" selected>Power (W)</option><option value="A">Current (A)</option><option value="V">Voltage (V)</option></select><div class="row"><div><label id="firstLabel" for="first">Voltage (V)</label><input id="first" value="12" inputmode="decimal"><p id="firstError" class="error"></p></div><div><label id="secondLabel" for="second">Current (A)</label><input id="second" value="2" inputmode="decimal"><p id="secondError" class="error"></p></div></div><div class="buttons"><button class="primary" type="submit">Calculate</button><button type="button" id="reset">Reset</button></div><p id="feedback" class="error" role="status"></p></form></section>
<section class="panel below"><h2>One relationship, three questions</h2><div class="equations"><div><strong>P = V × I</strong><p>12 V × 2 A = 24 W</p></div><div><strong>I = P ÷ V</strong><p>24 W ÷ 12 V = 2 A</p></div><div><strong>V = P ÷ I</strong><p>24 W ÷ 2 A = 12 V</p></div></div><h3>Substitution record</h3><pre class="record" id="record"></pre><p class="muted">Fictional educational values. Two known quantities are required; 10 W alone cannot determine volts. Inverse equations require a positive denominator. No AC, RMS, power factor, wiring, ratings, efficiency or energy/runtime inference.</p><p class="muted">Manual input scope: 0–1,000,000; at most six decimal places. Values use only the units shown. Tiny positive results retain scientific notation; approximate displays have up to six decimal places.</p><a href="https://openstax.org/books/physics/pages/19-4-electric-power">OpenStax: P = IV relationship</a></section><footer class="muted below">Local working copy · Changes are not saved after this page closes.</footer></main><script data-app>
(()=>{
const $=id=>document.getElementById(id);const text=(id,v)=>$(id).textContent=String(v);const on=(id,type,fn)=>$(id).addEventListener(type,fn);const escapeHTML=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));const decimal=s=>{const raw=String(s).trim();if(!/^[0-9]+(?:[.][0-9]{1,6})?$/.test(raw)||!Number.isFinite(+raw)||+raw>1000000)throw Error('Use a number from 0 to 1,000,000 with at most six decimal places. Blank is missing.');return +raw};const display=n=>n>0&&n<0.000001?n.toExponential(6):Number(n.toFixed(6)).toString();const download=(name,content,type='text/plain')=>{const url=URL.createObjectURL(new Blob([content],{type})),a=document.createElement('a');a.href=url;a.download=name;document.body.append(a);a.click();a.remove();setTimeout(()=>URL.revokeObjectURL(url),1000)};
const modes={W:{name:'Power',labels:['Voltage (V)','Current (A)'],units:['V','A'],symbol:'P',op:'×'},A:{name:'Current',labels:['Power (W)','Voltage (V)'],units:['W','V'],symbol:'I',op:'÷'},V:{name:'Voltage',labels:['Power (W)','Current (A)'],units:['W','A'],symbol:'V',op:'÷'}};
function solve(mode,x,y){if(!Object.hasOwn(modes,mode))throw Error('Choose the unknown quantity.');if(mode!=='W'&&y<=0)throw Error(modes[mode].labels[1]+' must be greater than zero for this division.');return mode==='W'?x*y:x/y}
function clear(){['answer','equation','record'].forEach(id=>text(id,'—'));['firstError','secondError'].forEach(id=>text(id,''));text('feedback','Inputs changed. Calculate to update.')}
function calculate(){clear();const m=$('mode').value;if(!Object.hasOwn(modes,m)){text('feedback','Choose the unknown quantity.');return}let x,y;for(const [i,id] of ['first','second'].entries()){try{const n=decimal($(id).value);if(i===0)x=n;else y=n}catch(e){text(id+'Error',modes[m].labels[i]+': '+e.message)}}if(x===undefined||y===undefined){text('feedback','Both known quantities are required.');return}try{const r=solve(m,x,y),c=modes[m];text('answer','≈ '+display(r)+' '+m);text('equation',c.symbol+' = '+x+' '+c.units[0]+' '+c.op+' '+y+' '+c.units[1]+' = '+display(r)+' '+m);text('record','Find: '+c.name+' ('+m+')\nAssumption: steady DC scalar magnitudes\nRaw known fields: '+JSON.stringify($('first').value)+' '+c.units[0]+', '+JSON.stringify($('second').value)+' '+c.units[1]+'\nParsed values: '+x+', '+y+'\nSubstitution: '+c.symbol+' = '+x+' '+c.op+' '+y+'\nInternal result: '+r+' '+m+'\nDisplayed: ≈ '+display(r)+' '+m);text('feedback','Calculated from both supplied quantities.')}catch(e){text('secondError',e.message);text('feedback','No result: inverse denominator is zero.')}}
function changeMode(){clear();const c=modes[$('mode').value];text('firstLabel',c?c.labels[0]:'First known quantity');text('secondLabel',c?c.labels[1]:'Second known quantity');text('unknownLabel',c?'Calculated '+c.name.toLowerCase():'Select the unknown');$('first').value='';$('second').value='';$('first').disabled=!c;$('second').disabled=!c}
on('mode','change',changeMode);['first','second'].forEach(id=>on(id,'input',clear));on('form','submit',e=>{e.preventDefault();calculate()});on('reset','click',()=>{$('mode').value='';changeMode();text('feedback','');$('mode').focus()});window.app={solve,calculate,changeMode};calculate();
})();
</script>
<script>
// Local calculation controls: no native form submission or sandbox permissions required.
(()=>{const form=document.getElementById('form');if(!form)throw Error('Calculation form missing');const dispatch=()=>form.dispatchEvent(new Event('submit',{bubbles:true,cancelable:true}));const buttons=[...form.querySelectorAll('button')].filter(button=>button.type==='submit');if(buttons.length!==1)throw Error('Expected one calculation control');for(const button of buttons){button.type='button';button.addEventListener('click',dispatch);}form.addEventListener('keydown',event=>{if(event.key==='Enter'&&!event.isComposing&&['INPUT','SELECT'].includes(event.target.tagName)){event.preventDefault();dispatch();}});})();
</script>
</body></html>