skip to Main Content
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)

terminal

node ‘.all functions.js’
Enter Two Numbers34
34
3434

Expected answer

node ‘.all functions.js’
Enter Two Numbers34
34
68

2

Answers


  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);
    
    Login or Signup to reply.
  2. var read = require("readline-sync")
    
    var a = read.questionFloat("Enter Two Numbers");
    var b = read.questionFloat("")
    
    function hello(num1, num2) {
      var sum = num1 + num2;
      return sum
    }
    
    var val = hello(a, b)
    console.log(val)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search