Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not convert string to number by using isFinite() #105

Open
ChopperLee2011 opened this issue Jun 28, 2017 · 2 comments
Open

Can not convert string to number by using isFinite() #105

ChopperLee2011 opened this issue Jun 28, 2017 · 2 comments

Comments

@ChopperLee2011
Copy link

ChopperLee2011 commented Jun 28, 2017

In the override Exercise, the tutorial suggests using isFinite() method to convert msg.left and msg.right to number and check if they are numbers, then sum values here. but after I run the code, it still concat two strings like '1' and '0' to '10', not 1.
And I make a example code here

@ChopperLee2011
Copy link
Author

ChopperLee2011 commented Jun 28, 2017

if I install this lib from npm, the test code in the seneca-override-executor.js is

 seneca.act({role: 'math', cmd: 'sum', left: process.argv[3], right: process.argv[4]}, function (err, result) {
    if (err) return console.error(err)
    console.log(result)
  })

which is not the same here.

@mmayla
Copy link

mmayla commented Oct 10, 2017

isFinite doesn't convert and return the string to number it just tests whether the string you provided is a finite number and return True or False.

to finish this exercise you have to convert the left and right arguments to numbers in the sum microservice using Number() global function.

this.add({role: 'math', cmd: 'sum'}, (msg, reply) => {
    const sum = Number(msg.left) + Number(msg.right);
    reply(null, {answer: sum})
  });

In an exercise after you will create an override microservice that convert left and right for all your math plugin microservices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants