scrimba  javascriptmas challenge

scrimba javascriptmas challenge

a 24-day coding challenge by scrimba

ยท

2 min read

ask 1 of the December coding challenge

it is another December which means it's javacriptmas in scrimba. It's a 24-day coding challenge aimed to improve beginners in mastering JavaScript.

the first task requires coders to implement the following :

  • writing a function that accepts a sentence

  • return that sentence in upper case

  • add (!) at the end of the sentence

  • check if the string is a sentence then return it with an emoji after each word

  • if it's a single-word string then just return it with conditions 2 & 3

Example input: "Hello"
Example output: "HELLO!"

Example input: "I'm almost out of coffee"
Example output: "I'M ๐Ÿ˜ฑ ALMOST ๐Ÿ˜ฑ OUT ๐Ÿ˜ฑ OF ๐Ÿ˜ฑ COFFEE!"

scrimba also provides a hint of concept that will help solve the task.

my approach

I first create a function using function expression and then give it a parameter. I use a conditional to check if the string has more than one word by using a split method with a space separator, that will turn the string into an array with sub-strings. then check if the string has more than 0 words which means it is a sentence.

if so the if statement would split the sentence, add the emoji and join back the string. if not it converts the string into upper case, adds (!) at end of it and returns the new string

solution

const panic = (word) => {

    if(word.split(' ').length > 0){
        return word.split(' ').join(' ๐Ÿ˜ฑ ').toUpperCase() + '!'
    }
    return word + '!'
}
ย