为什么num1+num2不计算

问题描述 投票:0回答:1
var read = require("readline-sync")

var a = read.question("Enter Two Numbers")
var b = read.question("")

function hello(num1,num2){
  var sum = num1 + num2
  return(sum)
}

var val = hello(a,b)

console.log(val)

终端

node'.llfunctions.js'
输入两个数字34
34
3434

预期答案

node'.llfunctions.js'
输入两个数字34
34
68

javascript function sum calculation
1个回答
-1
投票
var read=require("readline-sync")

var a = read.question("Enter Two Numbers");
var b = read.question("")

function hello (num1,num2) {
  var sum = Number(num1) + Number(num2); // convert string to number
  return sum;
}

var val = hello(a,b);

console.log(val);
© www.soinside.com 2019 - 2024. All rights reserved.