Home > database >  How to add two numbers from event in a lamba function with node.js
How to add two numbers from event in a lamba function with node.js

Time:01-19

I'm trying to add to numbers together and put them in my dynamodb database , it works , but everytime i try it just put them side by side without adding them, exemple (50 50=5050 and not 100)

Here's what i tried

"Total": { "S": event.First event.Second }

CodePudding user response:

Firstly I can see you save them as a String, do you wish to do so or would it be better as a number? I am also assuming that your numbers are coming into the event as Strings:

let num1 = parseInt(event.First);
let num2 = parseInt(event.Second);
let total = num1   num2

let params = {
"pk": { "S": "123" },
"Total": { "N": total.toString() }
}
  • Related