topskill.dev
CoursesTracks
0
All courses/Introduction to JavaScriptWhat is JavaScript?
Introduction to JavaScript
1 / 10
← Introduction to JavaScript
●What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking○Missing values and deliberate emptiness○Inspect Values in the Console○Inspect the Queue Report○Trace a Faulty Calculation○Repair the Score Calculation✦Module Quiz
○Declaring Variables○let and const in Practice○Operators○Type Conversion○Group and Convert Expense Inputs○Calculate the Event Expense Total○Track a Changing Points Tally○Adjust a Ticket Price✦Module Quiz
○Comparisons and strict equality○Truthiness and combined conditions○Function inputs and results○Conditionals○Combined Conditions Before FizzBuzz○Challenge: FizzBuzz Announcer○Switch Statement○Switch a Venue Sign○Challenge: Power Loadout○For Loops○While Loop○Break and Continue○Stop a Ticket Scan○Challenge: Number Guess Referee○Rainfall Routing Walkthrough○Score Batch Report✦Module Quiz
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions○Ticket Pricing Walkthrough○Shipping Labels with Defaults○Seat Ledger Closure Walkthrough○Private Budget Ledger✦Module Quiz
○Arrays○Student Scoreboard○Challenge: Student Course Scoreboard○Array Mutation Methods○Array Slice and Concat○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every○Charging Rack Restock Report○Pantry Restock Plan✦Module Quiz
○Object Key-Value Pairs○Student Course Record○Object Methods and Destructuring○Object copies and optional properties○Map and Set Collections○Playlist Lookup○Number and BigInt Boundaries○Ticket Ledger○JSON○Throwing and catching errors○Math and Date○Date Basics○Supply Bin Audit○Volunteer Shift Audit○Workshop Attendance Feed○Parcel Scan Feed✦Module Quiz
○String Methods○Template Literals○Regular Expressions○Build a Reminder with Template Literals○Format Pantry Pickup Messages○Validate a Time Slot with Regex○Validate Storage Shelf Labels✦Module Quiz
○Higher-Order Functions○Callbacks○map, filter, and reduce○Student Register with map○Challenge: Student Register○Recursion○Project - Data Transform Pipeline○Extend the inventory report○Handle an Error-First Callback○Report Seat Reservation Results○Summarize Completed Bike Rides○Summarize Delivered Parcels✦Module Quiz
○A notebook object○OOP Introduction○Independent workshop passes○Classes○An inherited notice○Inheritance○A private seat counter○Encapsulation○Equipment desk checkout○Project: Library Checkout✦Module Quiz
○Callback Timing○Asynchronous JavaScript○Promise Rehearsal○Promises and Async Await○Offline API Coordination○Async API Simulation○Partial Results Bulletin○Project: Resilient Awards Feed○Retry a Local Delivery○Project: Reliable Score Delivery✦Module Quiz

What is JavaScript?

You have used HTML for structure and CSS for appearance. The Starline Awards scoreboard still needs a calculation. In this one bridge lesson, connect index.html to script.js and show a calculated result in the page. The remaining lessons in these sections use only script.js and the Console.

Run the starter: the preview paragraph is blank, and the Console shows the two unfinished values. You will fill those values in one at a time before displaying their combined message. Leave the supplied HTML in place.

A statement is one instruction. JavaScript runs these statements from top to bottom. In const notice = "Exhibit open";, const creates a name, = assigns its first value, and the quotes mark text. The semicolon ends the statement. Change the value on the right of =, not the name on the left.

The browser supplies document, the page-access API; it is not part of the JavaScript language itself. We will learn that API in the next, vanilla DOM course. Here the page-output line uses document.getElementById("output") to find the supplied paragraph, then assigns its textContent. For step 3, replace the empty string with a backtick string containing ${introMessage} | ${introNumber}. You do not need to write any other page code.

In a saved web page, the script tag loads the file. This learning preview also injects your JavaScript so it can run edited code; removing the tag may not stop the preview, but the connection is still required for a standalone page.

JavaScript runs in the browser and powers the interactive parts of the web. This first coding lesson keeps the idea simple: store a message, calculate a number, and show both on the page.

HTML, CSS, and JavaScript have different jobs

  • HTML gives the page its structure and content.
  • CSS controls the visual presentation.
  • JavaScript calculates, decides, and responds to input. This first lesson writes a result into the page only so you can see how the two files connect.

Include JavaScript from HTML

index.html contains the page shell and includes this line near the end of <body>:

html
<script src="script.js"></script>

That src value is the filename. When you save these two files in the same folder, the browser reads index.html, reaches the script tag, and loads script.js.

The built-in editor combines the tabs into a preview when you press Run; it does not publish a separate script.js at the lesson's web address. Both tabs are visible here to show the connection. From the next lesson onward, you will work in script.js and the Console only.

Example

const gives a value a name. In the last line, ${...} inserts a value into the backtick-delimited message. The Console displays the result; the starter's document.getElementById("output").textContent displays it on the page instead. You will study these tools in more detail later.

javascript
const notice = "Exhibit open";
const visitors = 4 * 6 - 1;
console.log(`${notice}: ${visitors}`);

The final window.introCheckpoint line is supplied so Submit can inspect the two values independently. Leave it in place, along with the checkpoint logs. Edit script.js, use Run to see the page and Console, then Submit to check your work.

Your Task

  1. Set introMessage to "JavaScript rocks!"; the provided probe will log message: JavaScript rocks!.
  2. Calculate introNumber as (5 * 3) + 2; the provided probe will log number: 17.
  3. Show JavaScript rocks! | 17 in #output using both values.
Hint 1
1 / 2
HINT 1

Store text in introMessage and the calculation result in introNumber.

HINT 2

Use document.getElementById('output') to show the final summary.

Files
  • ⋄index.html
  • ⋄script.js
Loading editor…