Giter Site home page Giter Site logo

Comments (4)

bethrobson avatar bethrobson commented on August 11, 2024

Hi there.
Did you try writing down the value of all the variables for each function call?
That's the easiest way to figure it out. Also remember clunkCounter is a global variable so all the references to clunkCounter in the functions are modifying that one global variable.

E.g. for size = 0:
facky = 1
clunkCounter = 0
call display() = clunkCounter = 1
We don't call clunk().
print clunkCounter, 1

For size = 1:
facky = 1
clunkCounter = 0
call display() = clunkCounter = 1
We don't call clunk()
print clunkCounter, 1

For size = 2:
facky = 1
clunkCounter = 0
facky = 1 * 2 = 2
size = 1
call clunk(2)
call display twice (because times = 2)
clunkCounter = 2
print clunkCounter, 2

And continue. Now you do this for size = 5.

from head-first-javascript-programming.

meelaik avatar meelaik commented on August 11, 2024

Hi Elisabeth,
thanks so much for answering :)

You have helped me a lot, but I still do not understand why we get 6 clunks when calling thingamajig with argument 3.

What's the main difference between the argument 2 and 3? (I think an explanation here would solve my problem... ;))

Thank you very much

from head-first-javascript-programming.

hrkoren avatar hrkoren commented on August 11, 2024

I agree! Sizes up through 2, make sense. After that is where I am getting lost - if itโ€™s a while loop, I still canโ€™t get it to work. Driving me nuts trying to figure out how this works.

from head-first-javascript-programming.

bethrobson avatar bethrobson commented on August 11, 2024

For size = 3:
facky = 1
clunkCounter = 0
while loop:
facky = 3
size = 2
facky = 6
size = 1
end while loop
call clunk(6)
num = 6
while loop
display clunk 6 times
increase clunkCounter 6 times to 6
end function calls
display clunkCounter, which is 6

from head-first-javascript-programming.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.