![](/img/trans.png)
[英]using a for loop in javascript write a code that prompts the user to enter any amount of numbers the print the largest and smallest of those numbers
[英]How to write a javaScript function to enter 2 numbers through prompts and display the sum of those numbers in an alert?
我想顯示這個:輸入您的號碼:第一:第二:答案:我嘗試這樣做:
var a = prompt("A : ", "");
var b = prompt("B : ", "");
function calc(a,b)
{
return a + b;
}
alert ("The addition is =" + calc(a,b);
只需一個提示即可:
var numbers = prompt("Enter two numbers separated by a semi-colon: ", "");
var a = numbers.split(";")[0];
var b = numbers.split(";")[1];
function calc(a,b)
{
return parseFloat(a) + parseFloat(b);
}
alert ("The addition of " + numbers + " is = " + calc(a,b));
您只需要解析提示中的返回
var a = prompt("A : ", ""); var b = prompt("B : ", ""); function calc(a,b) { return parseFloat(a) + parseFloat(b); } alert ("The addition is =" + calc(a,b));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.