From bc26f639148eac03696d210d94be8aca93394970 Mon Sep 17 00:00:00 2001 From: ningnong239 Date: Fri, 25 Jul 2025 03:57:31 +0700 Subject: [PATCH] feat:add functionality --- ex-1.js | 5 +++++ ex-2.js | 7 +++++++ ex-3.js | 10 +++++++++- ex-4.js | 12 +++++++++++- ex-5.js | 22 ++++++++++++++++++++++ ex-6.js | 3 +++ 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/ex-1.js b/ex-1.js index d94e927..a73c664 100644 --- a/ex-1.js +++ b/ex-1.js @@ -2,3 +2,8 @@ let lightBulbStatus = "On"; // Start coding here. +if (lightBulbStatus === "On") { + console.log(`Light bulb is ${lightBulbStatus}`); +} else { + console.log("Light bulb is OFF"); +} \ No newline at end of file diff --git a/ex-2.js b/ex-2.js index 4a8bace..8ef91d9 100644 --- a/ex-2.js +++ b/ex-2.js @@ -2,3 +2,10 @@ let lightBulbStatus = "On"; // Start coding here. +if (lightBulbStatus === "On"){ + console.log(`Light Bulb is ${lightBulbStatus}`); +} else if ( lightBulbStatus === "Off"){ + console.log(`Light Blub is ${lightBulbStatus}`); +} else if( lightBulbStatus === "Broken"){ + console.log(`Light bulb is ${lightBulbStatus}`); +} \ No newline at end of file diff --git a/ex-3.js b/ex-3.js index 44940ad..6a9803b 100644 --- a/ex-3.js +++ b/ex-3.js @@ -2,4 +2,12 @@ // Ternary Operator let lightBulbStatus = "Off"; -//Start coding here \ No newline at end of file +//Start coding here +const message = + lightBulbStatus ==="On" + ? "Light bulb is On." + : lightBulbStatus === "OFF" + ? "Light bulb is Off." + : "Please choose the correct input (On/Off)" + +console.log(message); \ No newline at end of file diff --git a/ex-4.js b/ex-4.js index e0ed60d..c90abae 100644 --- a/ex-4.js +++ b/ex-4.js @@ -2,4 +2,14 @@ // Switch Statement let lightBulbStatus = "On"; -//Start coding here \ No newline at end of file +//Start coding here +switch (lightBulbStatus) { + case "On": + case "Off": + case "Broken": + console.log(`Light bulb is ${lightBulbStatus}`); + break; + default: + console.log(`มองดูหลอดไฟของคุณพี่ก่อนจ้า`); + break; +} \ No newline at end of file diff --git a/ex-5.js b/ex-5.js index 19536b2..abbb5d3 100644 --- a/ex-5.js +++ b/ex-5.js @@ -1,6 +1,28 @@ function calculateStudentGrade(score) { // Start coding here } +if (score > 100 || score < 0) { + return "F"; +} + + if ( score >= 90){ + return "A"; + } + + if (score >= 80){ + return "B"; + } + + if (score >= 70){ + return "C"; + } + + if (score >= 60){ + return "D"; + } + + return " Check your Score"; +} // Example case let johnGrade = calculateStudentGrade(30); diff --git a/ex-6.js b/ex-6.js index a0906de..9a6a71a 100644 --- a/ex-6.js +++ b/ex-6.js @@ -3,6 +3,9 @@ let favoriteBooks = []; function addFavoriteBook(bookName) { // Start coding here ! } +if (bookName.includes("Beauty")){ + favoriteBooks.push(bookName); +} // Example case addFavoriteBook("Let Me Tell You What I Mean");