Help with Reusable Function

Hi All,

i don´t know if it´s the right place but i´m blocked.

I´m doing the course of Java, and i´m in this exercise:

function functionWithArgs(one, two) {

    console.log(one + two);

} 

functionWithArgs(1, 2);

functionWithArgs(7, 9);

with these params it´s working fine, however I want mix text and numbers, someone could let me know if i can do it, if yes how?

I have moved your post to it’s own topic. How would you like to mix text and numbers? Adding a letter and a number isn’t always well defined.


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

try and see what happens if you call the function with strings as arguments or with a string and a number

1 Like

if you can’t get the answer click help and see the solution in get hint.

I don’t recommend looking around to copy the answers to challenges instead of trying to ask questions and figure them out.

Guys sorry if I wasn’t clear.

I put the example with the correct answer.

However I was asking about the possibility to use a parameter that contains letters and numbers.

And I test it and don’t works. I just add a number, I put a string with number, and don’t work too.

what have you tried? show please that

The addition operator ( + ) produces the sum of numeric operands or string concatenation, so if you are passing a string will treat all as strings and concatenate them

add(1, "2") // "12" trated as string and concatenated

If you want to always treat them as numbers you need to be explicit about it :slight_smile:
Hope it helps.

1 Like

Million thanks, I was expecting a way to not treat all as string.

It’s answered no thank you all