How do I bring a const in js to my div in html? [closed]

1 day ago 2
ARTICLE AD BOX

You can’t “call constants back to HTML”. JavaScript must read values after user input and update the DOM.

Your code also has casing errors and runs too early.

function getValues() { const a = document.getElementById('a_value').value; const b = document.getElementById('b_value').value; const c = document.getElementById('c_value').value; document.getElementById('result').textContent = `a=${a}, b=${b}, c=${c}`; }

Call the function from HTML (e.g., button click):

<button onclick="getValues()">Get values</button> <p id="result"></p>

Key point: HTML doesn’t access JS variables; JS updates HTML via the DOM.

Read Entire Article