Category: javascript

This Chest Doesn’t Need a Key, It Has AI!

Some treasure is locked away with keys.Some with secret codes.Mine is guarded by artificial intelligence. Recently, I set out to build something fun, interactive, and educational—a pirate-themed treasure chest made from cardboard that could open and close on its own. But instead of a simple switch, I wanted to give it a brain. That’s where […]

Sorting words using the sort() method

You’ve been given an array of words and asked to sort them in alphabetical order. Wow, that was easy! Here’s how it works: The sort() method is used to rearrange the elements of an array in ascending order by default. However, the default sorting behavior is based on converting elements to strings and comparing their […]

Sorting numbers with the sort() method

You’ve been given an array of numbers and asked to sort them in ascending order. Let’s take a look… Well, that’s not right! Here’s why: The default behavior of the sort() method in JavaScript is to convert elements to strings before performing comparisons. This can sometimes lead to unexpected results when sorting numbers. Instead, you’ll […]