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
aswordblanks
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
andmyAdverb
!!So, at the last you can see that we are calling the function called
wordblanks
and in that we're passing in a noun asdog
, an adjective asbig
, an verb asran
and an adverb asquickly
!๐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"));
EXPLANATION:
- So, what I have done after
var = " "
isresult +=
We have used+=
to add somethings using theseNoun, Adjective, Verb and Adverb
I have addedThe
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!!โค