Home > Blockchain >  Text with variable in one line [HTML JS] (and the Ultimate Question of Life, the Universe, and Every
Text with variable in one line [HTML JS] (and the Ultimate Question of Life, the Universe, and Every

Time:12-12

The program works correctly so far. But I want the solution to be answered in one line. So that's what I programmed so far:

    <h3>Answer to the Ultimate Question of Life, the Universe, and Everything</h3>
    <button onclick="myFunction()">calculate</button>
    <p>The Answer to the Ultimate Question of Life, the Universe, and Everything is:
    <p id="wert">not answered
    <p>, nice!
    <script>
    function myFunction() {
    var x = 42;
    document.getElementById("wert").innerHTML = x;
    }
    </script>

Thank you, I appreciate your help!

CodePudding user response:

you could use an inline element, like a <span>

<h3>Answer to the Ultimate Question of Life, the Universe, and Everything</h3>
    <button onclick="myFunction()">calculate</button>
    <p>The Answer to the Ultimate Question of Life, the Universe, and Everything is:
    <span id="wert">not answered
    </span>
    </p>, nice!
    <script>
    function myFunction() {
    var x = 42;
    document.getElementById("wert").innerHTML = x;
    }
    </script>

  • Related