top of page

This code is basically a small pH simulator. It lets you move a slider from pH of 0 to 14 and see what happens to a solution as it becomes more acidic or more basic.

When you move the slider, the simulation takes that pH value and uses it to calculate the hydrogen ion concentration. Since pH is defined as the - log [H+], the code just does [H+] = 10^−pH to get the concentration. Then it uses the formula [OH-]= (1.0×10^−14)/[H+] to calculate the hydroxide ion concentration so that the math always stays consistent, and pOH= -log[OH-] is 14-pH.

The beaker in the middle is just a visual, but it’s meant to represent what a real solution would look like if you added a universal indicator. The color changes based on common indicator charts you see in chemistry classes. Acids show up red or yellow, neutral solutions are green, and bases turn blue or purple. The colors aren’t smooth on purpose because indicator charts usually show ranges, not exact shades.

There’s also a label that switches between acidic, neutral, and basic. Neutral is kept pretty close to pH 7 instead of being a huge range, since chemically that’s the point where [H+] and [OH−] are equal.

Overall, the code is just trying to connect the math behind pH with something you can actually see. Instead of just numbers, it shows how changing pH affects ion concentrations and indicator color at the same time, which makes the concept easier to understand.

STAY IN THE KNOW

Thanks for submitting!

© 2025 by The STEMiscope. All rights reserved.

bottom of page