JavaScript for Beginners!   Part-4๐ŸŒ’

JavaScript for Beginners! Part-4๐ŸŒ’

ยท

3 min read

Hieee Coders!!๐Ÿ˜Ž

So, This is the Part-4 of Javascript for Beginners!!

And in Part-1 we had learned about Printing Statements, Variables in JS and Arithmetic Operators. Remember??

Also in Part-2 we had learned about Incrementing numbers, Decrementing numbers, Shortcuts :(*=, /=), Add 1 to number, Escape sequences in strings๐ŸŽƒ

In Part-3 we had learn about Concatenating strings with plus operator ๐ŸŽ“, Concatenating strings with plus equals operator๐ŸŽฉ, Constructing strings with variables๐Ÿ“ŒActivity!!๐Ÿ‘ฉโ€๐Ÿ’ป, Find Length of string๐ŸŽ—,Bracket Notations to find the characters of strings๐ŸŽฒ Bracket Notations to find the last letter!๐Ÿ›’

If you have not seen my Part-1, Part-2 and Part-3 go watch now because in that 3 articles we have talked about the basic things in JS!๐Ÿ‘จโ€๐Ÿ’ป

Topic:๐Ÿ‘‡

Word Blanks!๐ŸŽณ (by using functions)

Basically word blanks can just make our mind more sharp or can make us clever!!๐Ÿ˜

We're going to use our knowledge of strings to build a Mad Libs style word game.๐ŸŽฎ

In the Mad Lib you are provided sentences with some missing words like Nouns, Verbs, Adjectives and Adverbs.๐Ÿ˜Ž

And then you fill in the pieces with words of you choice, to make a sentence that could be funny and hopefully can make a bit of sense. So, lemme show you how you do this. This also uses a function, now we have not talked about functions yet. I am gonna explain them more later.๐Ÿ˜‰

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";

  return result;
}

console.log(wordBlanks("dog", "big", "ran", "quickly"));

Explanation :

  • So, here we've called a function as wordblanks you can call the function for any name you want!!

  • And you have to pass in a certain types of words like I've passed myNoun, myAdjective, myVerb and myAdverb!!

  • So, at the last you can see that we are calling the function called wordblanks and in that we're passing in a noun as dog, an adjective as big, an verb as ran and an adverb as quickly!๐Ÿ˜€

  • So, the point is that we are going to use these all words that are passed in to make a sentence.

  • So, we know that var = an empty string at first and then we have to use all these words in result. And then the result is going to be returned from this function. And eventually, it'll be logged out onto this screen with this console.log.
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  result +=
    "The " + myAdjective + myNoun + myVerb + " to the garden " + myAdverb;

  return result;
}

console.log(wordBlanks("dog ", "big ", "ran ", "quickly"));

image.png

EXPLANATION:

  • So, what I have done after var = " " is result += We have used += to add somethings using these Noun, Adjective, Verb and Adverb I have added The and then SPACE.
  • After "The " I have putted plus operator (+). Then our myAdjective (big) again (+), Then our myNoun (dog) again (+), Then our myVerb (ran) again (+) then "to the garden " and Then our myAdverb (quickly)
  • Last and the final step is putting the spaces like: "dog " at the last in the noun, adjective, verb!๐Ÿ˜€

Hopefully you are done with the Word Blanks!!๐Ÿ’œ But I want you to make this but by using different words!!

Challenge!๐Ÿ‘ฉโ€๐Ÿ’ป (On Functions)

Now, you are going to have a Challenge on Functions. Basically you have to do the same as you have done above! I am gonna give some words and you need to make a sentence that make sense through these words!!โ›ณ

Words:

  • Noun = "bike"
  • Adjective = "slow"
  • Verb = "flew"
  • Adverb = "slowly"

Best of Luck!๐Ÿ’š

If you do this challenge then you are the PRO in Javascript for beginners!!๐Ÿ˜Ž๐Ÿค‘

Motivation for today: Programming isn't what you know; It's about what you can figure out.๐Ÿ™Œ

So guys this was the Part-4 so I'll see you all again in the Part-5(tomorrow) till then byee!!โค

ย