Theoretical recap.
In JavaScript ES6+, a program often needs to react to information provided at runtime.
You have already seen variables, let, const, primitive types, number, string, boolean, type conversions, arithmetic operators, template literals, and if-slash-else conditions with comparison operators.
This workshop combines all of these.
Mental model.
Think of your script as a small decision machine.
It receives an input, an age, transforms it into the correct type, compares it against a rule, the legal majority threshold of 18, and produces a personalized message.
Input arrives as text, so it must be converted before any numeric comparison.
Key definitions.
Prompt reads a value from the user and always returns a string.
Number or parse and convert that string into a number.
And if slash else block chooses which branch of code runs based on that Boolean.
Common mistakes.
Comparing a string to a number without converting.
18 greater than equals 18 works by coercion, but relying on this is fragile.
Forgetting that empty or non-numeric input produces nan-an.
Using equals, assignment, instead of equals equals equals, strict comparison, and concatenating messages with plus instead of using cleaner template literals.
Mini-example.
Const age text equals prompt your age? Const age equals number age text.
If age greater than equals 18, console.log you are of legal age, dollar age.
Else, console.log you are a minor, dollar age.
This is the exact foundation you will extend below.
Read the full transcript.
Create an account to read the whole episode, search across every transcript, and follow the shows you care about.
Theoretical recap.
In JavaScript ES6+, a program often needs to react to information provided at runtime.
You have already seen variables, let, const, primitive types, number, string, boolean, type conversions, arithmetic operators, template literals, and if-slash-else conditions with comparison operators.
This workshop combines all of these.
Mental model.
Think of your script as a small decision machine.
It receives an input, an age, transforms it into the correct type, compares it against a rule, the legal majority threshold of 18, and produces a personalized message.
Input arrives as text, so it must be converted before any numeric comparison.
Key definitions.
Prompt reads a value from the user and always returns a string.
Number or parse and convert that string into a number.
And if slash else block chooses which branch of code runs based on that Boolean.
Common mistakes.
Comparing a string to a number without converting.
18 greater than equals 18 works by coercion, but relying on this is fragile.
Forgetting that empty or non-numeric input produces nan-an.
Using equals, assignment, instead of equals equals equals, strict comparison, and concatenating messages with plus instead of using cleaner template literals.
Mini-example.
Const age text equals prompt your age? Const age equals number age text.
If age greater than equals 18, console.log you are of legal age, dollar age.
Else, console.log you are a minor, dollar age.
This is the exact foundation you will extend below.