1. Hello World
A program can start with one instruction. console.log() prints text to the terminal. This is where every programmer begins.
Code — copy, change and run
console.log("Hello World!");For ordinary Node.js snippets, save as lesson1.js and run node lesson1.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
Hello World!
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/hello · Source: index.js
Your challenge: Change the text to Hello Programmer's Picnic and run it again.
Knowledge check: Does console.log() display output in the terminal or the browser's webpage?
It prints to the terminal when Node.js runs your .js file.
2. Hello Name
Store a name in a variable, then join text using the + operator. Our GoDaddy route accepts ?name= in the URL.
Code — copy, change and run
const name = "Champak";
console.log("Hello " + name + "!");For ordinary Node.js snippets, save as lesson2.js and run node lesson2.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
Hello Champak!
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/hello-name?name=Champak · Source: index.js
Your challenge: Change the name to a friend's name. What changes in the output?
Knowledge check: What is the purpose of const name?
It creates a variable named name whose value is not reassigned.
3. Add 2 Numbers
Read two numbers, add them and display the result. Numbers must be numbers, not strings: Number('5') converts a numeric string to a number.
Code — copy, change and run
const a = 12;
const b = 8;
const sum = a + b;
console.log(sum);For ordinary Node.js snippets, save as lesson3.js and run node lesson3.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
20
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/add?a=12&b=8 · Source: index.js
Your challenge: Add 125 and 375. Explain what happens if a and b are strings.
Knowledge check: What is "5" + "2" in JavaScript?
It is "52" because both inputs are strings. Use Number() to get 7.
4. Subtract 2 Numbers
Use subtraction to find the difference between two values. Order matters: a - b is different from b - a.
Code — copy, change and run
const a = 20;
const b = 7;
console.log(a - b);For ordinary Node.js snippets, save as lesson4.js and run node lesson4.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
13
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/subtract?a=20&b=7 · Source: index.js
Your challenge: Try 7 - 20. Why is the result negative?
Knowledge check: Does a - b always equal b - a?
No. Subtraction depends on the order of the numbers.
5. Multiply 2 Numbers
Multiplication uses * instead of the × symbol. You can multiply whole numbers, negative numbers and decimal values.
Code — copy, change and run
const a = 6;
const b = 7;
console.log(a * b);For ordinary Node.js snippets, save as lesson5.js and run node lesson5.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
42
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/multiply?a=6&b=7 · Source: index.js
Your challenge: Find the area of a 12 × 9 rectangle using multiplication.
Knowledge check: Which JavaScript operator multiplies two values?
The asterisk: *.
6. Divide 2 Numbers
Division uses /. A program should reject division by zero instead of producing an unusable answer.
Code — copy, change and run
const a = 20;
const b = 4;
if (b === 0) {
console.log("Cannot divide by zero");
} else {
console.log(a / b);
}For ordinary Node.js snippets, save as lesson6.js and run node lesson6.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
5
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/divide?a=20&b=4 · Source: index.js
Your challenge: Enter zero as the second number. Observe how the API reports an input error.
Knowledge check: Why do we check b === 0 before dividing?
Because division by zero is invalid for this beginner calculator.
7. Even or Odd
The % operator gives the remainder. An integer is even if n % 2 is zero; otherwise it is odd.
Code — copy, change and run
const n = 9;
if (n % 2 === 0) {
console.log("Even");
} else {
console.log("Odd");
}For ordinary Node.js snippets, save as lesson7.js and run node lesson7.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
Odd
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/even-odd?n=9 · Source: index.js
Your challenge: Try 0, -4 and 101. Predict their results first.
Knowledge check: What is 10 % 2?
0, so 10 is even.
8. Largest of 3 Numbers
We can compare numbers with >, but Math.max() is a shorter way to find the largest value.
Code — copy, change and run
const a = 7;
const b = 25;
const c = 19;
console.log(Math.max(a, b, c));For ordinary Node.js snippets, save as lesson8.js and run node lesson8.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
25
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/largest?a=7&b=25&c=19 · Source: index.js
Your challenge: Try three equal numbers. Is the largest value still well-defined?
Knowledge check: Which standard JavaScript function gives the largest number?
Math.max().
9. Multiplication Table
A loop repeats an instruction. Here it prints multiples of a number from 1 to 10. Change the limit to see more rows.
Code — copy, change and run
const n = 3;
for (let i = 1; i <= 10; i++) {
console.log(n + " × " + i + " = " + n * i);
}For ordinary Node.js snippets, save as lesson9.js and run node lesson9.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
3 × 1 = 3 3 × 2 = 6 ... 3 × 10 = 30
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/table?n=3&upto=10 · Source: index.js
Your challenge: Generate the table of 13 up to 20 rows.
Knowledge check: What is the role of i++ in the for loop?
It increases i by one after each loop iteration.
10. Factorial
n! means 1 × 2 × 3 × ... × n. We start with 1, not 0, because zero would make every product zero.
Code — copy, change and run
const n = 5;
let factorial = 1;
for (let i = 2; i <= n; i++) {
factorial *= i;
}
console.log(factorial);For ordinary Node.js snippets, save as lesson10.js and run node lesson10.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
120
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/factorial?n=5 · Source: index.js
Your challenge: Find 0!, 6! and 10!. Why is 0! equal to 1?
Knowledge check: Why do we initialize factorial to 1?
1 is the multiplicative identity; multiplying by it preserves the first factor.
11. Fibonacci Series
Each number in the Fibonacci sequence is the sum of the previous two. It starts with 0 and 1.
Code — copy, change and run
let a = 0, b = 1;
for (let i = 0; i < 7; i++) {
console.log(a);
[a, b] = [b, a + b];
}For ordinary Node.js snippets, save as lesson11.js and run node lesson11.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
0 1 1 2 3 5 8
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/fibonacci?count=7 · Source: index.js
Your challenge: Print the first 12 terms. What is the value after 8?
Knowledge check: What is the next value after 0, 1, 1, 2, 3, 5?
8, since 3 + 5 = 8.
12. Array: Sum and Average
Arrays store many values. reduce() can add all the values; sum divided by count gives the average.
Code — copy, change and run
const numbers = [10, 20, 30];
const sum = numbers.reduce((a, b) => a + b, 0);
const average = sum / numbers.length;
console.log(sum, average);For ordinary Node.js snippets, save as lesson12.js and run node lesson12.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
60 20
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/array-stats?numbers=10%2C20%2C30 · Source: index.js
Your challenge: Find the total, average, minimum and maximum of 4, 8, 12, 16.
Knowledge check: What does numbers.length return?
The number of elements in the array.
13. Palindrome Check
A palindrome reads the same forwards and backwards. We normalize the text before comparing it to its reverse.
Code — copy, change and run
const text = "Madam";
const clean = text.toLowerCase().replace(/[^a-z0-9]/g, "");
const reverse = [...clean].reverse().join("");
console.log(clean === reverse);For ordinary Node.js snippets, save as lesson13.js and run node lesson13.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
true
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/palindrome?text=Madam · Source: index.js
Your challenge: Test racecar, hello and Never odd or even.
Knowledge check: Why do we use toLowerCase() here?
To treat uppercase and lowercase letters as equivalent.
14. Marks to Grades
A real program often chooses between several possibilities. The checks are evaluated from highest mark band to lowest.
Code — copy, change and run
const marks = 80;
let grade;
if (marks >= 90) grade = "A";
else if (marks >= 75) grade = "B";
else if (marks >= 60) grade = "C";
else if (marks >= 40) grade = "D";
else grade = "F";
console.log(grade);For ordinary Node.js snippets, save as lesson14.js and run node lesson14.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
B
Try it yourself
Run in browser uses local JavaScript. Test on GoDaddy makes a real request to the selected preview API; if that private preview blocks external requests, the browser result still works for learning.
Server route: /api/grade?marks=80 · Source: index.js
Your challenge: Test boundary values 39, 40, 59, 60, 74, 75, 89 and 90.
Knowledge check: Why do we test marks >= 90 before marks >= 75?
Because a mark of 95 satisfies both; the first matching branch wins.
15. Return JSON
An API returns structured information as JSON. NodeUse sends a status code and application/json response that frontend code can read.
Code — copy, change and run
const http = require("node:http");
http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ message: "Hello World!" }));
}).listen(3000);For ordinary Node.js snippets, save as lesson15.js and run node lesson15.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
{"message":"Hello World!"}
Server route: /api/hello · Source: index.js
Your challenge: Change the JSON object to include a name and a lesson number.
Knowledge check: What does JSON.stringify() do?
It converts a JavaScript value into JSON text to send in an HTTP response.
16. Fetch Data from Node.js
fetch() makes an HTTP request. We check response.ok and parse JSON. The frontend needs the exact API hostname and permission to read cross-origin responses.
Code — copy, change and run
const api = "https://11vhaiejwu.c39.airoapp.ai";
async function sayHello() {
const response = await fetch(api + "/api/hello");
if (!response.ok) throw Error("HTTP " + response.status);
const data = await response.json();
console.log(data.message);
}
sayHello();For ordinary Node.js snippets, save as lesson16.js and run node lesson16.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
Hello World! GitHub Pages is connected to Node.js on GoDaddy.
Server route: /api/hello · Source: index.js
Your challenge: Fetch /api/add?a=5&b=10, then print its result.
Knowledge check: What is the purpose of await response.json()?
It waits for the JSON response body to be parsed into a JavaScript value.
17. HTML Form to Node.js
An HTML form collects values. Build a URL with URLSearchParams to safely encode those values before calling the Node.js API.
Code — copy, change and run
const values = new URLSearchParams({ a: "5", b: "10" });
const api = "https://11vhaiejwu.c39.airoapp.ai";
fetch(api + "/api/add?" + values)
.then(res => res.json())
.then(data => console.log(data.result));For ordinary Node.js snippets, save as lesson17.js and run node lesson17.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
15
Server route: /api/add?a=5&b=10 · Source: index.js
Your challenge: Replace the fixed numbers with values from two input elements.
Knowledge check: Why is URLSearchParams better than simply joining strings?
It correctly URL-encodes parameter names and values.
18. Deploy on GoDaddy + CORS
The backend runs on GoDaddy; this course's HTML is hosted on GitHub Pages. Our public, read-only demonstration API now uses Access-Control-Allow-Origin: *, so students can call it from any website without credentials. This is not a suitable default for private user data or authenticated endpoints. A Failed to fetch message can also mean that GoDaddy's published app is offline or has not received the latest deployment.
Code — copy, change and run
// Public read-only examples — no accounts or cookies:
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
// Handle OPTIONS preflight with HTTP 204.
// Never use public wildcard access for sensitive account data.For ordinary Node.js snippets, save as lesson18.js and run node lesson18.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
GET /health → {"status":"ok","service":"nodeuse-hello-api","apiVersion":"2026-10-30-jsonp-fallback"}
Server route: /health · Source: index.js
Your challenge: Deploy the latest main branch with Update Preview, test /health, then Publish to Live. Never commit preview share tokens.
Knowledge check: Does wildcard CORS provide user authentication?
No. Wildcard CORS only permits browser access to public responses. Private user data requires proper authentication and authorization.
19. Build a Task Manager
Put the basics together: enter a task, list tasks, change its status and delete it. The current app saves tasks in this browser's localStorage; the GoDaddy API does not yet store tasks.
Code — copy, change and run
let tasks = JSON.parse(localStorage.getItem("tasks") || "[]");
tasks.push({ id: Date.now(), name: "Study Node.js", done: false });
localStorage.setItem("tasks", JSON.stringify(tasks));
console.log(tasks);For ordinary Node.js snippets, save as lesson19.js and run node lesson19.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
[{ "id": 1234567890, "name": "Study Node.js", "done": false }]
Your challenge: Open the Task Manager and create, edit, complete, search and delete a task.
Knowledge check: Will localStorage tasks appear automatically on another computer?
No. localStorage data belongs to the current browser and origin, not the GoDaddy server.
20. Infinity: REST API and Database
Next, build authenticated GET/POST/PATCH/DELETE routes, database storage, secure login, and proper server-side authorization. Do not expose an unauthenticated public write API.
Code — copy, change and run
// Future production API design (not yet implemented):
// GET /api/tasks list my tasks
// POST /api/tasks create my task
// PATCH /api/tasks/:id update my task
// DELETE /api/tasks/:id delete my task
// Always authenticate and authorize each request.For ordinary Node.js snippets, save as lesson20.js and run node lesson20.js. Browser-only snippets are identified by their use of fetch, localStorage or page inputs.
Expected output
Roadmap only — these task endpoints are not live yet.
Your challenge: Design a Task table with id, userId, title, status, and createdAt. Which routes must require login?
Knowledge check: Why must a public task API check authorization?
To ensure each user can only view or change tasks they are permitted to access.
Connect to your published GoDaddy API
The practice buttons use the published GoDaddy Node.js API below. If its proxy blocks CORS, the course tries a JSONP fallback for these public, read-only programs; never use JSONP for private data. GoDaddy preview links are private and can block public browser requests. To update the server, click Update Preview and then Publish to Live in GoDaddy. Do not include any preview sharing token.
Test /api/hello on the published GoDaddy app.
Deployment check: Open /api/diagnostics directly. The expected apiVersion is 2026-10-30-jsonp-fallback and allowOrigin is *. If the direct page fails, verify the exact published app URL in GoDaddy. If the version is old, publish the newest commit. When the direct JSON link works but normal fetch is blocked, the lesson tries a clearly labeled JSONP fallback for these public-only examples.