Ask coding questions

← Back to all posts
How can I change the clock to AM and PM
h
p1ckl3

I have been working on a kaboom game recently and have been trying to get a clock working. I have the clock and all I need is a system to say AM or PM. What am I doing wrong?

The code is on lines 105-112 file main.js

Voters
p1ckl3
Comments
hotnewtop
OldWizard209

Here is literally all the code you need to make a working clock in JS:

This checks if time is greater than 12 (because javascript's Date class displays time in 24 hr format) we change the period to PM, and subtract the new time by 12 so you get the Om time :)

AmoghTheCool

@okalisl to get whether it is AM or PM you can use a ternary operator:

I don't really know HOW you are getting the time but that ternary operator should work.

p1ckl3

Ok I changed line 101 is this what you mean?

AmoghTheCool
AmoghTheCool

@okalisl or you may be getting the wrong time

p1ckl3

Hmm this isn't working @AmoghTheCool do you know if they're any other issues?

AmoghTheCool

@okalisl no i looked at your code you did the ternary operator wrong - the ternary operator returns not a boolean but a string