var perimeterBox = function(length, width) {
return (length * 2) + (width * 2);
};
var justAsk = prompt("what is the length, width?");
perimeterBox(justAsk);
当我运行它时会弹出提示。但是当我输入长度,宽度(例如:7,3)时,我得到一个null值。以为?
答案 0 :(得分:1)
您需要从用户输入的字符串中提取值:
var perimeterBox = function(length, width) {
return (length * 2) + (width * 2);
};
var justAsk = prompt("what is the length, width?"); // justAsk is "7,3"
var values = justAsk.match(/\d+/g); // values is ["7", "3"]
var width = parseInt(values[0]); // width is 7
var height = parseInt(values[1]); // height is 3
perimeterBox(width, height);