DEV Community

Milan Matejic
Milan Matejic

Posted on

2 2

JavaScript assignments - 3

It's time for another JavaScript assignment.

This assignment is great to practice JavaScript and develop problem solving thinking.

If you have another solution, please be kind and write it in the comment section.

Assignment:
Write a program to create a new string adding "New :)!" in front of given string. If given string begins with "New :)!" already, then return the original string.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
Solution:

const newStr = (str) => {
  if (str.includes("New :)!")) {
    return str;
  } else {
    return "New :)! " + str;
  }
};

console.log(newStr("mouse is the cats worst enemy"));
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay