Add two numeric values in pre-request script

First of all, thanks to everyone who posts in the community, as a relative newbie I have found it really useful to get to know Postman and all the responses are super friendly and helpful.

But I’m stuck on something and I know it should not be that hard.

In a pre-request Script I want to set two random numeric variables between 0-100.99 < done
But I then want the average of these two values
My plan was to add value01+value02 = sum
then sum/2 = average
the average part works with one value,
the bit I can’t seem to figure out is how to add two values!
if value01 = 50.29 and value02 = 20.10 for example, I want sum = 70.39
but I get 50.2920.10

I have tried math, calculate, everything I can think of.

here is my example

const first1 =("first1", _.random(0,100))
const second1=("second1", _.random(0,99))
const value01 = first1 +"."+ second1
const first2 =("first2", _.random(0,100))
const second2 =("second2", _.random(0,99))
const value02 = first2 +"."+ second2
let sum =  value01 + value02
let average = sum / 2
pm.globals.set("value01",value01);
pm.globals.set("value02",value02);
pm.globals.set('sum', sum);
pm.globals.set('average', average);

as I say, I’m a newbie so any help or advice is much appreciated

figured it out while the post was been reviewed.

let sum =  +value01 + +value02

I needed the + before the value to declare it as a number

1 Like