← Back to Artizan Software
Students hunched over desks surrounded by towering stacks of math homework

The Math Dilemma

Challenge 2

When Mr. Sterling swaggered into our ninth-grade math class, you could've mistaken him for a pirate captain boarding a captured ship. With an eye-patch missing and a parrot short of looking the part, he eyed us as though we were his newest recruits. His voice, dripping with sarcasm, boomed, "Congratulations, lucky ones! Tonight's prize is 300 math problems!"

Tim, always one to wear his heart on his sleeve, looked horrified. "Sir, are we training to be calculators or what?"

Mr. Sterling leaned in, his eyes narrowing, "Why, Tim, I thought you loved challenges! And here I was, thinking I was being generous."

Days turned into blurry-eyed nights. The school's atmosphere shifted from a place of learning to what felt like a survivor's camp. Maya, once the beacon of style, now sported mismatched socks and hair that looked like it had been styled by a tornado. One day, Jack came in with two different shoes, and nobody even noticed. It was every student for themselves.

In the midst of this chaos, an idea struck me. I sought out Tom, the class's resident tech wizard. If rumors were to be believed, Tom could hack a toaster to butter your bread. "Tom," I whispered, "can we... you know... outsmart Mr. Pirate— I mean, Sterling?"

In his room, amidst the scent of soldering iron and half-eaten snacks, our master plan took shape. Tom's fingers flew across the keyboard, and together, we created a software genius that could make those treacherous math problems walk the plank.

News of our secret weapon spread faster than a cat meme on the internet. Our once-beleaguered classmates now whispered excitedly, sharing tales of their math conquests.

But Captain Sterling wasn't born yesterday. Sensing mutiny, he announced with exaggerated shock, "Oh dear! It seems you're all becoming too smart. So, how about we double the fun? 600 problems tonight!"

The class groaned, but Tom, ever the confident one, just winked, "Trust the process."

Then, D-Day arrived: the surprise quiz. The atmosphere was so tense, you could've cut it with a protractor. But thanks to our trusty software, we were more than ready to parry every curveball Sterling threw.

Just as we thought we were in the clear, in sailed Principal Fernandez with a bombshell. "Thanks to Mr. Sterling's... unique teaching methods," she said, with a twinkle in her eye, "our school's been awarded for 'Innovative Torture— I mean, Teaching Techniques'."

The class roared with laughter, even drowning out Sterling's sarcastic clap. Flushing a shade that could rival a tomato, he admitted, "Alright, perhaps I did get a bit carried away."

As the bell rang, Tom and I shared a triumphant fist bump. The math monsoon had passed, and we had navigated through it, compass and map in hand. The legend of the ninth-grade pirates was born!

· · ·

Create Software to Solve Math Problems

In the story, Tom wrote software that could crunch through hundreds of math problems. In JavaScript, we can do the same thing with just a few lines. Let's learn how variables and arithmetic work.

Storing a Number

let radius = 5.2; — Variables store information. This one holds a number with a decimal point. Think of it as a labeled jar with the number 5.2 inside.

Famous Numbers

let pi = 3.14159; — You can store any number you need. Pi is one of the most famous numbers in mathematics, and now it lives inside a variable.

Doing the Math

let circumference = 2 * pi * radius; — JavaScript can do math. Multiply with *, add with +, subtract with -, and divide with /. This line calculates a circle's circumference.

Displaying the Result

console.log("The circumference is: " + circumference); — You can combine text and numbers to display results. The + here joins the label with the calculated value.

Now it's your turn. Use the playground below to run the math, then try changing the radius and running again!