DEV Community

Cover image for Edabit challenge 2 | strings | very easy | Return Something to Me!
codeWithNithin
codeWithNithin

Posted on

Edabit challenge 2 | strings | very easy | Return Something to Me!

Write a function that returns the string "something" joined with a space " " and the given argument a.
giveMeSomething("is better than nothing") ➞ "something is better than nothing"

giveMeSomething("Bob Jane") ➞ "something Bob Jane"

giveMeSomething("something") ➞ "something something"

// solutions

// method 1

// with regular
function giveMeSomething(str) {
  return `Something ${str}`;
}

// with arrow
const giveMeSomething = (str) => `something ${str}`;

// method 2

// with regular
function giveMeSomething(str) {
  return "Something " + str;
}

// with arrow
const giveMeSomething= (str) => "something " + str;


// conclusion
// always use template literal to concat a string, since its easier to use, so use the below code

function giveMeSomething(str) {
  return `something ${str}`;
}

// with arrow
const giveMeSomething= (str) => `something ${str}`;
Enter fullscreen mode Exit fullscreen mode

Latest comments (0)