Let’s try to understand step by step :
- In the code, I have taken four variables speakWord, names, firstLetter and i.
- In speakWord, there are two strings one is “Hello” and another one is “Good Bye”.
- In names, we have taken some strings, here we are taking few names as a variable.
- In firstLetter, at first, we are changing the first letter to lower case and then we are checking if it is ‘j’ or not.
- i is an integer. we are using i to set a condition.
- In the code there are three functions speak(), helloSpeaker and byeSpeaker.
- speak(), it just prints the Hello or Good Bye and the names according to the condition.
- In helloSpeaker, after checking the condition that the first letter does not start from ‘J’ or ‘j’ it prints the string which says Hello + name.
- In byeSpeaker, after checking the condition that the first letter is from ‘J’ or ‘j’ it prints the string which says Good Bye + name.
To check the output go to the console and check it.
( for chrome -> right click -> inspect element -> console tab )
You may also learn,