Comments (4)
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.
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.
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.
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)
- Global Variable. HOT 1
- Object Magnets - Page : 221 || Mistake HOT 1
- Why can't I set an attribute to an element through JS ? HOT 2
- typeof array ?? HOT 2
- Missing resources for rock.png and cookies.js HOT 1
- Question re Battleship game in Ch. 8: why functions are not part of our objects? HOT 1
- What is the license for the source in this repository? HOT 5
- Object Magnets Solution (pg. 221) HOT 1
- Chapter 13 Robot game solution (p. 583 in pdf book) HOT 2
- For the Blur/zeroBlur image exercise
- object name HOT 2
- Chapter 8 - Battleship HOT 17
- How/where do we call the isSunk method in chapter 8 ?
- Chapter 8 - Battleship game.
- Chapter 4. Bubbles 2. HOT 2
- Chapter 8. Onkeypress is deprecated.
- Appendix RegExp, Recursion and JS Algorithms Practice HOT 2
- battleship game in chapter 2 is flawed !!! HOT 4
- JavaScript - Pass-by-value || Page 92 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from head-first-javascript-programming.