DEV Community

Milan Matejic
Milan Matejic

Posted on

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)