CodeOrbit

🏁

Orbit Reached

You have completed all mission contexts.

Context 30 / 30

Method Chaining

You can attach tools back-to-back. word.trim().toUpperCase() first cleans the spaces, then immediately capitalizes the result in one smooth motion.

Context 29 / 30

Immutability of Strings

Once a string is created, the original cannot be altered. Methods like toUpperCase() don't change the original word; they spit out a brand new copy of it.

Context 28 / 30

String Methods: endsWith()

Checks if the string ends with specific characters. Great for checking if a file upload ends in '.jpg' or '.png'.

Context 27 / 30

String Methods: startsWith()

Checks if the string begins with specific characters. Useful for checking if a URL starts with 'https://'.

Context 26 / 30

String Methods: includes()

Returns a simple true or false. sentence.includes('alien') checks if the word 'alien' exists anywhere inside the sentence.

Context 25 / 30

String Methods: trim()

Users accidentally add spaces when typing. trim() shaves off invisible spaces from the far left and far right of a string, cleaning up the data.

Context 24 / 30

String Methods: split()

A powerful tool that chops a string into pieces and turns it into an Array list. Splitting a sentence by spaces creates an array of individual words.

Context 23 / 30

String Methods: replaceAll()

Regular replace() only targets the very first match it finds. replaceAll() hunts down every single instance in the entire paragraph and changes them all.

Context 22 / 30

String Methods: replace()

Finds a specific word inside a sentence and replaces it. sentence.replace('bad', 'good') swaps the first instance of 'bad' with 'good'.

Context 21 / 30

String Methods: substring()

Almost identical to slice, but it refuses to accept negative numbers. If you give it a negative, it treats it as a zero.

Context 20 / 30

slice() with Negatives

If you give slice a negative number, like slice(-2), it counts backward from the end of the word, extracting the last two letters.

Context 19 / 30

String Methods: slice()

Acts like a pair of scissors. word.slice(0, 3) cuts out the letters starting at position 0 and ending at position 3. It pulls out a sub-section.

Context 18 / 30

String Methods: indexOf()

Acts like a search engine for your word. word.indexOf('e') tells you exactly which numerical position the letter 'e' is located at within the string.

Context 17 / 30

String Methods: toLowerCase()

The exact opposite. Converts all characters to lowercase. A must-have for checking email addresses in a database.

Context 16 / 30

String Methods: toUpperCase()

Instantly converts the entire string to capital letters. Useful for normalizing user input so 'yes', 'Yes', and 'YES' all look identical to the computer.

Context 15 / 30

Accessing Characters

You can pluck a single letter out of a word using brackets. If word = 'Code', word[0] gives you 'C'.

Context 14 / 30

Index Positions

Computers start counting at zero. In the word 'APPLE', 'A' is at position 0, 'P' is at position 1. This zero-based counting is a core rule of programming.

Context 13 / 30

The Length Property

Typing 'password.length' tells you exactly how many characters are in the string. If the user typed '1234', the length is 4.

Context 12 / 30

Deep Dive: Strings

We know strings are text, but JS treats strings like an Array of characters. The word 'Cat' is actually treated as three separate letters: C, a, t.

Context 11 / 30

Math.PI

Need the exact value of Pi for circle calculations? You don't need to type 3.14159... Just type Math.PI and the computer provides the exact value.

Context 10 / 30

Math.sqrt()

Calculates the square root of a number. Math.sqrt(25) returns 5. Highly useful for calculating distances in video games or mapping software.

Context 9 / 30

Math.pow()

The older way to do exponents before '**' existed. Math.pow(2, 3) means 2 to the power of 3.

Context 8 / 30

Math.max() & Math.min()

Give it a list of numbers, and it finds the largest (max) or smallest (min). Math.max(10, 50, 2) instantly spits out 50.

Context 7 / 30

Creating a Dice Roll

To get a number from 1 to 6, you combine tools: Math.floor(Math.random() * 6) + 1. It scales the random decimal up, chops off the tail, and shifts it.

Context 6 / 30

Math.random()

Generates a random decimal between 0.0000 and 0.9999. It is the core engine for dice rolls, enemy spawns, and random events in coding.

Context 5 / 30

Math.trunc()

The butcher. It completely chops off the decimal and leaves the whole number, ignoring rounding rules entirely. 4.99 becomes 4.

Context 4 / 30

Math.ceil()

The ceiling function. It always pushes a decimal up to the next whole number. 4.1 becomes 5. Useful when you need whole buckets to hold items.

Context 3 / 30

Math.floor()

The gravity function. It always pulls a decimal down to the nearest whole number. 4.9 becomes 4. It never rounds up.

Context 2 / 30

Math.round()

Rounds a number to the nearest integer, just like in school. 4.4 becomes 4. 4.6 becomes 5.

Context 1 / 30

The Math Object

JS comes with a built-in calculator called the 'Math' object. It contains pre-written tools to handle complex numbers so you don't have to invent the formulas.

← Abort Mission

Lecture 04: Operators, Maths and Strings

Total Duration: 1 hrs 55 mins 27 secs

Initiate Launch Scroll UP to ignite thrusters