javascript - Javascript multiple functions
问题描述
I need to make a domain with the following:
- Ask the user for his or her name.
- Prompt the user for a number between 1 and 100 both included.
- Prompt the user for a number between 10 and 20 both included. <
- Give an output with the following text:
"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>
解决方案
有你想要的代码运行。如果要在 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>
推荐阅读
- vue.js - 在 Vue 中使用标签搜索 Flickr API
- xamarin - 关闭应用程序时的 Xamarin Android 服务
- python - 当我将主 Flask python 文件移动到模块中时,`gcloud app deploy` 会抛出`No module named 'main'`
- random-forest - 随机森林模型的 F1 分数
- salt-stack - saltstack 为长时间运行的进程实时获取命令执行标准输出
- html - 某些屏幕分辨率上不需要的空白
- php - XAMPP Apache 不会以修改后的 php5ts.dll 启动
- angular - Angular Observer 用户是否登录
- python - 接缝插入坐标 - 接缝雕刻
- postgresql - 是否有解决方法来确保在 jsondoc->>'....' 相等查询上仅扫描索引?