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)

Advice For Junior Developers

Advice from a career of 15+ years for new and beginner developers just getting started on their journey.