My homework for today :

Write a script that will output the numbers of the Fibonacci sequence.

https://void.cat/d/3smeRV3HFcv5UzR2kjmL2h.webp

Reply to this note

Please Login to reply.

Discussion

I don’t think you need two, nested for loops for this.

I could have done it with only one you reckon?

Yee. There are some programming problems (like sorting) where one would need to nest loops, but this problem can be solved with just one loop. What do you think?

Give it a try!

I'll go back at it, less code is better code for sure.

Thanks for the encouragement !

You can do it! 💪

Put 2 parameters in the first loop?

Backing up a second, I need some clarification. Will addFibs() be called more than once? Or will it be called only once?

Called once, with the numberOfFibs parameter specifing how many iterations of the first for loop.

OK, in that case, what happens if you just delete the outer for-loop? That is, what if you start right off with the of statement for length===0?

Oh yeah I see that now ! The step by step procedure I was sticking to got in my own way! Yeah , that code is utterly redundant.

💪

Nicely done, good sir

Thank you kindly!

You're telling me that works as expected?

It does , yes.

Well that's nice. Did you try asking chatgpt (or gpt4) to improve it?

No.