Js Lab
Js Lab
• switch (dayOfWeek) {
• case "Monday":
• schedule = "Work";
• break;
• case "Tuesday":
• case "Wednesday":
• case "Thursday":
• case "Friday":
• schedule = "Work";
• break;
• case "Saturday":
• case "Sunday":
• schedule = "Weekend";
• break;
• default:
• schedule = "Unknown";
• }
• console.log("Today's schedule:", schedule);
• // Example: Loops in JavaScript
• console.log("For loop:");
• for (let i = 0; i < 5; i++) {
• console.log("Iteration", i);
• }
• // Example: for...in loop in JavaScript
• // Define an object with some properties
• const person = {
• name: "Alice",
• age: 30,
• city: "New York"
• };
• // Iterate over the properties of the object using for...in loop
• console.log("Properties of the person object:");
• for (let key in person) {
• console.log(key + ": " + person[key]);
• }
• // While loop
• console.log("\nWhile loop:");
• let j = 0;
• while (j < 5) {
• console.log("Iteration", j);
• j++;
• }
• // Do-while loop
• console.log("\nDo-while loop:");
• let k = 0;
• do {
• console.log("Iteration", k);
• k++;
• } while (k < 5);
• // Example: Functions in JavaScript
• // Define a function called add that returns the sum of two numbers
• function add(a, b) {
• return a + b;
• }