Random function problem ,need help

#1

In this node, red I want to generate random number between 0-10 and if the number is less than 5 I want to output: the ((generated number from the function )) along with string message such as” less than 5”
for example :slight_smile: 4 less than 5
I can only output the generated number from the random function and I don’t know how to output string with it, I need help please.

#2

What do you by 'along with'? Do you mean a single string containing the number and text, or you want the number and message separately in one message?

#3

https://www.google.co.uk/search?q=append+string+javascript&ie=UTF-8&oe=UTF-8&hl=en&client=safari

#4

When I try to use (+) operator, I get an error as you see

#5

yes mean single string containing the number and text.

#6

You always need to return objects not variables.

But you should be able to concatenate within that object

eg

number = 5;
msg.payload = “the number is :” + number;
return msg;

#7

@sana_sabah86 - function debugging hint; do display sometthing in the debug log you can use:
node.warn("randon is: " + rnd);
and it will show with all the other debug messages.

#8

it worked! thank you so much for your helo

#9

thank you