Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCheryl Oliver
21,676 PointsMultiplication in Javascript
Can someone help me with this please? Using your favourite programming language, write a short bit of code to output all the times tables from 1 to 12. i.e.: 1 x 1 = 1; 1 x 2 = 2; etc, through to 12 x 1 = 12; 12 x 2 = 24; etc.
1 Answer
Steven Parker
231,248 PointsWhat course asks you to use "your favourite programming language"?
But anyway... This sounds like a job easily managed with two nested loops and an output statement.
Here's how it might look in Python:
for multiplicand in range(1, 13):
for multiplier in range(1, 13):
print("{} x {} = {}".format(multiplicand, multiplier, multiplicand * multiplier))
print()
Uriah Nevins
1,121 PointsUriah Nevins
1,121 PointsI wish this was a challenge I could accept. It sounds fun but I am not fluent in any programming languages yet. Although I would be interested to see someone's java code, just to see how they would do it.
Cheryl Oliver
21,676 PointsCheryl Oliver
21,676 PointsHi Steven, Thanks but I dont know how to do a nested loop, can you show me?
Steven Parker
231,248 PointsSteven Parker
231,248 PointsWhat course is this for? Can you give a link to a video or challenge?
"Nested" just means "one inside the other". And I added a sample to my answer.
Oops, I forgot this was the JavaScript forum (it was that "favorite language" thing). Here's the same example in JavaScript: