Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Now in the next lesson I've got a nother coding challenge for you.
And the idea of the coding challenge is for you to be able to replicate the Fibonacci sequence so the
Fibonacci sequence is very simple.
Essentially let's say that the first two digits start with zero and one every subsequent number in this
sequence is created by adding the two previous numbers.
So for example three is from one plus two.
Five comes from two plus three.
31 comes from 13 plus 21.
So it's a really really simple sequence.
Now your goal is to create a function where you can call it by simply writing Fibonacci generator parentheses
and then you put an inside and n is going to be the number of items in the sequence that you want to
create.
So for example if you want to get the first three items in the seven R2 sequence then you should be
at to call Fibonacci generator pass in the number three and get 0 1 1 as an array as the output.
Now there's a couple of things to note before you start tackling the challenge.
First is that the solution checker is going to expect an array as the output with square brackets and
commas that separate each number.
The next thing is do not change any of the existing code.
The solution checker is going to look for this function Fibonacci generator and pass in a number.
So if you change any of the existing code it might not work and it might think that you've written the
code wrong instead.
Next you do not need any alerts or prompt and the result should in fact be returned from this function
as an output next.
The first two numbers in the sequence must be 0 and 1.
There are many versions of the Fibonacci sequence.
Some start from one some start from zero but in our version it's going to start from zero and then the
next one is going to be 1.
So whenever you're generating any sort of sequence the first two numbers must be 0 and 1.
Now the final thing to say is that if you're going to use a for loop in your code make sure that you
write it like this.
So you create AI as an explicit variables use a var i equals zero as the first part of the for loop
rather than simply writing I equals zero.
This is just because the version of JavaScript that's being used to check the code has this specific
requirement.
Now you don't have to use a for loop.
You could use a while loop you can use anything that you're comfortable with.
Now finally I've got this replica playground here.
And if you click on it you'll get taken to a sandbox on Rappler where you can play around with your
code and see if it actually does what it's expected to do.
Now if all goes well and I'm scrolling down to hide my solution code here.
But if you manage to write the code correctly you should be able to create a variable code output which
is going to store the output that's returned from your function Fibonacci generator.
And if we pass in a number let's say 5 and we run our code then it should give us an array containing
5 items and the 5 items will be the first 5 numbers in the sequence.
So as we said it must start from zero and then 1 and then the next one comes from 0 plus 1.
The next one comes from one plus one etc. etc. and this should work even when this number is 1 or if
it's 2 or if it's some crazy large number.
Like 245.
Now the hardest part of this challenge is nailing down the logic and you really have to think carefully
to yourself what do all of those rules mean.
And one of the best ways of untangling the logic before you start writing code is to just create a flowchart
so you can easily create a flowchart by going to a website like draw IO and you can start mapping out
what the logic has to look like.
And then once you've got the flowchart then you can use that to create your code.
Now I've created a flowchart for you if you want to have a go at thinking about the logic and solving
the challenge yourself then pause the video now and continue to the next lesson and start the challenge.
But if you want a few hints I'll walk you through the logic in my flowchart All right.
So if you're still here.
Let's walk through this flowchart.
Let's say that we're going to call the function Fibonacci generator and parse in five as the value of
n..
So we start from our flowchart and we check first is n 1.
If it's yes then we're going to output just an array with the first number which is zero.
If it's no then we're going to check further is and 2 in which case we'll give the output as an array
with 0 and 1.
These two are the ones that we can't calculate.
They're the first two items of the array and they're just predefined.
Now if that question also gives us a no because in our case N is actually equal to 5.
Well in this case we have to sum the last two values.
So zero plus one is going to be one.
So now we've got an array that looks like this.
Now at this stage we have to ask ourselves does an equal the number of items in the output.
So the number of items in our output is 1 2 3 while N equals 5.
So no.
So we go back to over here and we sum the last two values again.
So in this case the last two values are 1 and 1.
So we now get two and then we continue this circle of logic until we get to the point where we have
the same number of items in our array five as the number and five will at this point then this output
is going to be sent out and returned from the function.
So this is the logic of the code that we need to write.
So now I have a think about this and I've got a link to this flowchart in the course resources if you
need to refer to it but have a good think about it and then head over to the next lesson and try to
tackle the challenge.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.