首页 > 解决方案 > Javascript multiple functions

问题描述

I need to make a domain with the following:

"Dear name of user the first number you entered was first number the second was second number. If we multiply these two number we get

So far I've gotten this:

function myFunction() {
  var person = prompt("Please enter your name", "enter name");
  if (person != null) {
    document.getElementById("demo").innerHTML =
      "Hello " + person + "! How are you today?";
  }

  function addNumbers() {

    var val1 = parseInt(document.getElementById("value1").value);
    val val2 = parseInt(document.getElementByID("value").value);
    var ansD = document.getElementByID("answer");
    ansD.value = val1 + val2;
  }
<p>Click the button to demonstrate the prompt box.</p>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

标签: javascripthtml

解决方案


有你想要的代码运行。如果要在 html 页面中输出结果,只需使用要更改的 id 的 innerHTML 方法即可。

<!DOCTYPE html>
<html>
<body>

<p>Click the button to demonstrate the prompt box.</p>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction() {
    var person = prompt("Please enter your name");
    var firstN = prompt("Please enter a number between 1 and 100");
    var secondN = prompt("Please enter a number between 10 and 20");
    document.getElementById("demo").innerHTML = "Dear "+person+" the first number you entered was "+firstN+" the second was "+secondN+". If we multiply these two number we get "+(firstN*secondN);
}
</script>

</body>
</html>

推荐阅读