diff --git a/JavaScripHYF/exercise.smart-ease.index.html b/JavaScripHYF/exercise.smart-ease.index.html new file mode 100644 index 000000000..e3ee9766b --- /dev/null +++ b/JavaScripHYF/exercise.smart-ease.index.html @@ -0,0 +1,13 @@ + + + + + + Document + + +

Test text

+ + + + diff --git a/JavaScripHYF/exercise.smart-ease.js b/JavaScripHYF/exercise.smart-ease.js new file mode 100644 index 000000000..f25d1a6f2 --- /dev/null +++ b/JavaScripHYF/exercise.smart-ease.js @@ -0,0 +1,148 @@ +//The full name exercise. +function getFullName(firstName, lastName,useFormalName ) { + let fullName =` ${firstName} ${lastName}` + + return useFormalName ? `Lord ${fullName}` : fullName; + +} + +const fullName1 = getFullName("John", "Doe"); +const fullName2 = getFullName("Jane", "Smith"); + +console.log(fullName1); +console.log(fullName2); + +// Event application +function getEventWeekday(numberOfDaysFromToday) { + const today = new Date(); + const targetDate = new Date(today); + targetDate.setDate(today.getDate() + numberOfDaysFromToday); + + const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; + const weekday = weekdays[targetDate.getDay()]; + + return weekday; +} + +console.log(getEventWeekday(9)); + +// Weather wear +function getWearByWeather(temperature) { + if (temperature < 0) { + return "Heavy winter coat, gloves, and a hat"; + } else if (temperature >= 0 && temperature < 10) { + return "Winter jacket and warm layers"; + } else if (temperature >= 10 && temperature < 18) { + return "Light jacket or sweater"; + } else + return "Shorts and a t-shirt"; +} + +const clothesToWear = getWearByWeather(18); +console.log(clothesToWear); + +//Student menager +const class07Students = []; + +function addStudentToClass(studentName) { + + if (studentName === 'Queen Mary') { + class07Students.push(studentName); + return; + } + + if (class07Students.includes(studentName)) { + console.log(`Student ${studentName} is already in the class`); + return; + } + + if (studentName=== '') { + console.log('You cannot add an empty name'); + return; + } + + if(class07Students.length >= 6) { + console.log('Cannot add more students to class 07'); + return; + } + + + class07Students.push(studentName); + +} + +function getNumberOfStudents() { + return class07Students.length; +} + +addStudentToClass('Alice'); +addStudentToClass('Bob'); +addStudentToClass('Charlie'); +addStudentToClass('David'); +addStudentToClass('Eve'); +addStudentToClass('Frank'); +addStudentToClass('Grace'); +addStudentToClass('Queen Mary'); +addStudentToClass(''); +addStudentToClass('Alice'); +addStudentToClass('Queen Mary'); + +console.log(getNumberOfStudents()); + +//Candy helper +const boughtCandyPrices = []; + +function addCandy(candyType, weight){ +let price; + if(candyType === "sweet"){ + price = 0.5 * weight; + } else if(candyType === "chocolate"){ + price = 0.7 * weight; + } else if(candyType === "toffee"){ + price = 1.1 * weight; + } else if(candyType === "chewing-gum"){ + price = 0.03 * weight; + } + boughtCandyPrices.push(price); + +} + +let amountToSpend = Math.random() * 100; + +function canBuyMoreCandy(){ + let totalSpent = 0; + for(let i = 0; i < boughtCandyPrices.length; i++){ + totalSpent += boughtCandyPrices[i]; + } + return totalSpent < amountToSpend; +} + +addCandy("sweet", 10); +if(canBuyMoreCandy()){ + console.log("You can buy more, so please do!"); +}else{ + console.log("Enough candy for you!"); +} + + +addCandy("chocolate", 5); +if(canBuyMoreCandy()){ + console.log("You can buy more, so please do!"); +}else{ + console.log("Enough candy for you!"); +} + +addCandy("toffee", 2); +if(canBuyMoreCandy()){ + console.log("You can buy more, so please do!"); +}else{ + console.log("Enough candy for you!"); +} + +addCandy("chewing-gum", 50); +if(canBuyMoreCandy()){ + console.log("You can buy more, so please do!"); +}else{ + console.log("Enough candy for you!"); +} + diff --git a/JavaScripHYF/exercise.voice-assistant.js b/JavaScripHYF/exercise.voice-assistant.js new file mode 100644 index 000000000..2935607da --- /dev/null +++ b/JavaScripHYF/exercise.voice-assistant.js @@ -0,0 +1,177 @@ + +let userName = null; +let todos = []; + +function getReply(command) { + console.log("Command received: ", command); + + if (command.includes("hello my name is")) { + let words = command.split(" "); + let nameIndex = words.length - 1; + let name = words[nameIndex]; + + if (userName == name) { + return "Hi again " + userName; + } + + userName = name; + return "Nice to meet you " + userName; + } + + if (command.includes("what is my name")) { + if (userName) { + return userName; + } else { + return "I don't know your name"; + } + } + + if (command.includes("to my to do")) { + let todo = command.slice(4, -11) + todos.push(todo); + return `${todo} added to your todo`; + } + + if (command.includes("from my todo")) { + let todo = command.slice(7, -1313); + let indexOfTodo = todos.indexOf(todo); + if (indexOfTodo !== -1) { + todos.splice(indexOfTodo, 1); + } + + return `Removed ${todo} from your todo`; + } + + if (command.includes("what is on my to do")) { + let numberOfItems = todos.length; + let responseSentence = `you have ${numberOfItems} todos - `; + + for (let i = 0; i < todos.length; i++) { + if (todos.length > 1) { + responseSentence += `${todos[i]}, `; + } else { + responseSentence += `${todos[i]} `; + } + } + return responseSentence; + } + + if (command.includes("what day is it today")) { + const date = new Date(); + let day = date.getDate(); + + const monthNames = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ]; + + let month = monthNames[date.getMonth()]; + + let year = date.getFullYear(); + + return `${day} of ${month} ${year}`; + } + + if (command.includes("what is ")) { + let fullOperationSentence = command.slice(8); + let partsOfSentence = fullOperationSentence.split(" "); + + let operatorSymbol = partsOfSentence[1]; + let number1 = parseInt(partsOfSentence[0]); + let number2 = parseInt(partsOfSentence[2]); + + let result; + + switch (operatorSymbol) { + case "+": + result = number1 + number2; + break; + + case "-": + result = number1 - number2; + break; + + case "*": + result = number1 * number2; + break; + + case "/": + result = number1 / number2; + break; + + default: + break; + } + + return result; + } + + if (command.includes("set a timer for")) { + let timerSentence = command.slice(16); + let partsOfSentence = timerSentence.split(" "); + let number = parseInt(partsOfSentence[0]); + let duration = partsOfSentence[1]; // seconds, minutes, hours + + let timerInMilliSeconds; + + switch (duration) { + case "seconds": + timerInMilliSeconds = number * 1000; + break; + + case "minutes": + timerInMilliSeconds = number * 1000 * 60; + break; + + case "hours": + timerInMilliSeconds = number * 1000 * 60 * 60; + break; + + default: + break; + } + + + function timerFunction() { + artyom.say("Timer Done"); + } + + setTimeout(timerFunction, timerInMilliSeconds); + + return `Timer set for ${number} ${duration}`; + } + + return "I didn't understand that command"; +} + +// getReply("hello my name is Monika"); +// getReply("hello my name is Monika"); +// getReply("hello my name is Benjamin"); + +// getReply("what is my name"); + +// getReply("add fishing to my todo"); +// getReply("add singing in the shower to my todo"); +// getReply("add boating to my todo"); +// getReply("add watching TV to my todo"); + +// getReply("remove fishing from my todo"); + +// getReply("what is on my todo"); + +// getReply("what day is it today"); + +// getReply("what is 3 + 3"); +// getReply("what is 4 * 12"); + +// getReply("set a timer for 5 seconds") \ No newline at end of file diff --git a/JavaScripHYF/exercise.week3.index.html b/JavaScripHYF/exercise.week3.index.html new file mode 100644 index 000000000..31f80d56d --- /dev/null +++ b/JavaScripHYF/exercise.week3.index.html @@ -0,0 +1,10 @@ + + + + + Document + + + + + \ No newline at end of file diff --git a/JavaScripHYF/exercise.week3.js b/JavaScripHYF/exercise.week3.js new file mode 100644 index 000000000..cdf4c8660 --- /dev/null +++ b/JavaScripHYF/exercise.week3.js @@ -0,0 +1,143 @@ +//Item array removal + +const names = [ + "Peter", + "Ahmad", + "Yana", + "kristina", + "Rasmus", + "Samuel", + "Katrine", + "Tala", +]; +const nameToRemove = "Ahmad"; + +// Write some code here +let index = names.indexOf(nameToRemove); +if (index > 0) { + names.splice(index, 1); +} +// Code done + +console.log(names); // ['Peter', 'Yana', 'kristina', 'Rasmus', 'Samuel', 'Katrine', 'Tala'] + + +//Speed and distance + +const travelInformation = { + speed: 50, + destinationDistance: 432, +}; + +function calculateTravelTime(travelInformation) { + let time = travelInformation.destinationDistance / travelInformation.speed; + let hours = Math.floor(time); + let minutes = Math.round((time - hours) * 60); + return `${hours} hours and ${minutes} minutes`; +} + +const travelTime = calculateTravelTime(travelInformation); +console.log(travelTime); + + +//Series duration... +const seriesDurations = [ + { + title: "Modern Family", + days: 5, + hours: 9, + minutes: 15, + }, + { + title: "Next gen chef", + days: 10, + hours: 23, + minutes: 55, + }, + { + title: "The night agent", + days: 10, + hours: 17, + minutes: 47, + }, +]; + +function logOutSeriesText(seriesDurations) { + + const lifeInMinutes = 80 * 365 * 24 * 60; + + seriesDurations.forEach((series) => { + + const seriesMinutes = + series.days * 24 * 60 + series.hours * 60 + series.minutes; + + const totalPercentage = ((seriesMinutes / lifeInMinutes) * 100); + + console.log(`${series.title} took ${totalPercentage.toFixed()}% of my life`); + }); +} + +logOutSeriesText(seriesDurations); + + +//Note taking app + +let notes = []; + +function saveNote(content, id) { + notes.push({ content: content, id: id }); +} + +function getNote(id) { + return notes.find((note) => note.id === id); +} + +function logOutNotesFormatted() { + notes.forEach((note) => { + console.log(`The note with id: ${note.id}, has the following note text: ${note.content}`); + }); +} + + +//Smartphone usage app + +let activities = []; + +function addActivity(date, activity, duration) { + activities.push({ date: date, activity: activity, duration: duration }); +} + +function showStatus(activities) { + + let activitiesNumber = activities.length; + let totalDuration = 0; + const usageLimit = 100; + + for (let i = 0; i < activities.length; i++) { + totalDuration += activities[i].duration; + } + + if (activitiesNumber === 0) { + console.log("Add some activities before calling showStatus"); + return; + } + + if (totalDuration > usageLimit) { + return "You have reached your limit, no more smartphoning for you!"; + } + + return `You have added ${activitiesNumber} activities. They amount to ${totalDuration} min. of usage`; + +} + +showStatus(activities); + +addActivity("2024-06-01", "Facebook", 35); +addActivity("2024-06-01", "Instagram", 20); +showStatus(activities); + +addActivity("2024-06-02", "YouTube", 200); +showStatus(activities); + + + diff --git a/JavaScripHYF/exercise1.index.html b/JavaScripHYF/exercise1.index.html new file mode 100644 index 000000000..31aaa9bed --- /dev/null +++ b/JavaScripHYF/exercise1.index.html @@ -0,0 +1,11 @@ + + + + + + Age calculator + + + + + \ No newline at end of file diff --git a/JavaScripHYF/exercise1.js b/JavaScripHYF/exercise1.js new file mode 100644 index 000000000..7c19dd449 --- /dev/null +++ b/JavaScripHYF/exercise1.js @@ -0,0 +1,65 @@ +// Age Calculator +let yearOfBirth = 1990; +let yearFuture = 2190; +let age = yearFuture - yearOfBirth; +console.log("You will be " + age + " years old in " + yearFuture); + +// Dog Age Calculator +let dogYearOfBirth = 2023; +let dogYearFuture = 2026; +let dogYear = dogYearFuture - dogYearOfBirth; +let shouldShowResultInDogYears = true; + +if (shouldShowResultInDogYears) { + let ageInDogYears = dogYear * 7; + console.log("Your dog will be " + ageInDogYears + " dog years old in " + dogYearFuture); +} else { + console.log("Your dog will be " + dogYear + " human years old in " + dogYearFuture); +} + +// House Price Calculator +housePrise = volumeInMeters = 2.5 * 1000 + gardenSizeInM2 * 300; + +let peterWidth = 8; +let peterDepth = 10; +let peterHeight = 10; +let peterGardenSizeInM2 = 100; +let peterHousePrice = 2500000; +let peterVolumeInMeters = peterWidth * peterDepth * peterHeight; +let peterCalculatedPrice = peterVolumeInMeters * 2.5 * 1000 + peterGardenSizeInM2 * 300; + +if (peterCalculatedPrice < peterHousePrice) { + console.log("Peter is paying too much."); +} else if (peterCalculatedPrice > peterHousePrice) { + console.log("Peter is paying too little."); +} else { + console.log("Peter is paying the correct price."); +} + +let juliaWidth = 5; +let juliaDepth = 11; +let juliaHeight = 8; +let juliaGardenSizeInM2 = 70; +let juliaHousePrice = 1000000; +let juliaVolumeInMeters = juliaWidth * juliaDepth * juliaHeight; +let juliaCalculatedPrice = juliaVolumeInMeters * 2.5 * 1000 + juliaGardenSizeInM2 * 300; + +if (juliaCalculatedPrice < juliaHousePrice) { + console.log("Julia is paying too much."); +} else if (juliaCalculatedPrice > juliaHousePrice) { + console.log("Julia is paying too little."); +} else { + console.log("Julia is paying the correct price."); +} + +// Startup name generator +let firstWords = ["Easy", "Awesome", "Corporate", "Red", "Blue", "Green", "Big", "Smart", "Nice", "Super"]; +let secondWords = ["App", "Solution", "Tech", "Systems", "Code", "Web", "Works", "Corp", "Data", "Cloud"]; + +let randomIndex = Math.floor(Math.random() * 10); +let startupName = firstWords[randomIndex] + " " + secondWords[randomIndex]; +let startupNameLength = startupName.length; + +console.log("The startup: " + startupName + " contains " + startupNameLength + " characters."); + + diff --git a/JavaScripHYF/exercises.API/Architecture- diagram.png b/JavaScripHYF/exercises.API/Architecture- diagram.png new file mode 100644 index 000000000..b6a641500 Binary files /dev/null and b/JavaScripHYF/exercises.API/Architecture- diagram.png differ diff --git a/JavaScripHYF/exercises.API/Diagram-edit recipe.png b/JavaScripHYF/exercises.API/Diagram-edit recipe.png new file mode 100644 index 000000000..e3bd140c3 Binary files /dev/null and b/JavaScripHYF/exercises.API/Diagram-edit recipe.png differ diff --git a/JavaScripHYF/exercises.API/Diagram-new recipe.png b/JavaScripHYF/exercises.API/Diagram-new recipe.png new file mode 100644 index 000000000..68f564bec Binary files /dev/null and b/JavaScripHYF/exercises.API/Diagram-new recipe.png differ diff --git a/JavaScripHYF/exercises.API/Diagram-specific recipe.png b/JavaScripHYF/exercises.API/Diagram-specific recipe.png new file mode 100644 index 000000000..1ef8e0962 Binary files /dev/null and b/JavaScripHYF/exercises.API/Diagram-specific recipe.png differ diff --git a/JavaScripHYF/exercises.API/exercise.Identify...txt b/JavaScripHYF/exercises.API/exercise.Identify...txt new file mode 100644 index 000000000..d0a3ba85e --- /dev/null +++ b/JavaScripHYF/exercises.API/exercise.Identify...txt @@ -0,0 +1,17 @@ + +Data storage: +Recipes are stored in a database (e.g. SQL or NoSQL) managed by the backend. Database has Recipes table which stores many recipes. Each recipe has fields like id, title, ingredients, instructions, etc. + +Frontend–backend communication: +The frontend communicates with the backend via REST API using HTTP requests, for example: +* GET /recipes – get all recipes +* GET /recipes/:id – get one recipe +* POST /recipes – create a recipe +* PUT /recipes/:id – update a recipe +* DELETE /recipes/:id – delete a recipe + +When a user adds a new recipe: +1. User fills and submits a form in the frontend. +2. Frontend sends a POST /recipes request with recipe data in JSON. +3. Backend validates and saves the recipe in the database, then returns the created recipe (with id). +4. Frontend updates the UI (e.g. adds the new recipe to the list or redirects to its detail view). diff --git a/courses/frontend/advanced-javascript/advanced-js-week2/function as a variable.exercise/script.js b/courses/frontend/advanced-javascript/advanced-js-week2/function as a variable.exercise/script.js new file mode 100644 index 000000000..c9879811d --- /dev/null +++ b/courses/frontend/advanced-javascript/advanced-js-week2/function as a variable.exercise/script.js @@ -0,0 +1,38 @@ +// create an array with 3 functions +const myFunctions = [ + function () { + console.log("Function 1"); + }, + function () { + console.log("Function 2"); + }, + function () { + console.log("Function 3"); + }, +]; + +myFunctions.forEach(function (fn) { + fn(); +}); + +// create a function as a const +const hello = function () { + console.log("Hello"); +}; + +// create a function normally +function hi() { + console.log("Hi"); +} + +hello(); +hi(); + +// create an object with a function as a value +const obj = { + speak: function () { + console.log("This is a function inside an object"); + }, +}; + +obj.speak(); diff --git a/courses/frontend/advanced-javascript/advanced-js-week2/functions.exercise/index.html b/courses/frontend/advanced-javascript/advanced-js-week2/functions.exercise/index.html new file mode 100644 index 000000000..b122883d9 --- /dev/null +++ b/courses/frontend/advanced-javascript/advanced-js-week2/functions.exercise/index.html @@ -0,0 +1,17 @@ + + + + + + Functions + + + + + + +
+ + + + diff --git a/courses/frontend/advanced-javascript/advanced-js-week2/functions.exercise/script.js b/courses/frontend/advanced-javascript/advanced-js-week2/functions.exercise/script.js new file mode 100644 index 000000000..241e9598a --- /dev/null +++ b/courses/frontend/advanced-javascript/advanced-js-week2/functions.exercise/script.js @@ -0,0 +1,124 @@ +// setTimeout function (exercise 1) +setTimeout(function () { + const paragraph = document.createElement("p"); + paragraph.innerText = "Called after 2.5 seconds"; + document.getElementById("output").appendChild(paragraph); +}, 2500); + +// function with 2 parameters: delay and stringToLog (exercise 2) +function logAfterDelay(delay, stringToLog) { + setTimeout(function () { + const paragraph = document.createElement("p"); + paragraph.innerText = stringToLog; + document.getElementById("output").appendChild(paragraph); + }, delay * 1000); +} + +logAfterDelay(1, "Called after 1 second"); +logAfterDelay(2, "Called after 2 seconds"); +logAfterDelay(3, "Called after 3 seconds"); + +// button click (exercise 3) +const button = document.getElementById("5secondsButton"); + +button.addEventListener("click", function () { + logAfterDelay(5, "Called after 5 seconds"); +}); + +// Earth and Saturn functions (exercise 4) +const earthLogger = function () { + const paragraph = document.createElement("p"); + paragraph.innerText = "Earth"; + document.getElementById("output").appendChild(paragraph); +}; + +const saturnLogger = function () { + const paragraph = document.createElement("p"); + paragraph.innerText = "Saturn"; + document.getElementById("output").appendChild(paragraph); +}; + +function logPlanet(planetLogFunction) { + planetLogFunction(); +} + +logPlanet(earthLogger); +logPlanet(saturnLogger); + +// Log location (exercise 5) +const locationButton = document.getElementById("locationButton"); + +locationButton.addEventListener("click", function () { + navigator.geolocation.getCurrentPosition( + function (position) { + const latitude = position.coords.latitude; + const longitude = position.coords.longitude; + + const paragraph = document.createElement("p"); + paragraph.innerText = `Latitude: ${latitude}, Longitude: ${longitude}`; + document.getElementById("output").appendChild(paragraph); + }, + function () { + const paragraph = document.createElement("p"); + paragraph.innerText = "Location not available"; + document.getElementById("output").appendChild(paragraph); + }, + ); +}); + +// run after delay function (exercise 7) +function runAfterDelay(delay, callback) { + setTimeout(function () { + callback(); + }, delay * 1000); +} + +const delayButton = document.getElementById("delayButton"); + +delayButton.addEventListener("click", function () { + const delayValue = Number(document.getElementById("delayInput").value); + + runAfterDelay(delayValue, function () { + const paragraph = document.createElement("p"); + paragraph.innerText = `This text was shown after ${delayValue} seconds`; + document.getElementById("output").appendChild(paragraph); + }); +}); + +// detect double click (exercise 8) +let lastClickTime = 0; + +document.addEventListener("click", function () { + const currentClickTime = Date.now(); + + if (currentClickTime - lastClickTime <= 500) { + const paragraph = document.createElement("p"); + paragraph.innerText = "double click!"; + document.getElementById("output").appendChild(paragraph); + } + + lastClickTime = currentClickTime; +}); + +// joke creator function (exercise 9) +function logFunnyJoke() { + const paragraph = document.createElement("p"); + paragraph.innerText = "Funny joke"; + document.getElementById("output").appendChild(paragraph); +} + +function logBadJoke() { + const paragraph = document.createElement("p"); + paragraph.innerText = "Bad joke"; + document.getElementById("output").appendChild(paragraph); +} + +function jokeCreator(shouldTellFunnyJoke, logFunnyJoke, logBadJoke) { + if (shouldTellFunnyJoke === true) { + logFunnyJoke(); + } else { + logBadJoke(); + } +} + +jokeCreator(true, logFunnyJoke, logBadJoke); diff --git a/courses/frontend/advanced-javascript/advanced-js-week2/game.exercise/index.html b/courses/frontend/advanced-javascript/advanced-js-week2/game.exercise/index.html new file mode 100644 index 000000000..12e94be12 --- /dev/null +++ b/courses/frontend/advanced-javascript/advanced-js-week2/game.exercise/index.html @@ -0,0 +1,20 @@ + + + + + + Fastest presser game + + + + + + +

+

S: 0

+

L: 0

+

+ + + + diff --git a/courses/frontend/advanced-javascript/advanced-js-week2/game.exercise/script.js b/courses/frontend/advanced-javascript/advanced-js-week2/game.exercise/script.js new file mode 100644 index 000000000..6740a4385 --- /dev/null +++ b/courses/frontend/advanced-javascript/advanced-js-week2/game.exercise/script.js @@ -0,0 +1,87 @@ +// Find the HTML elements +const gameTimeInput = document.getElementById("game-time"); +const startButton = document.getElementById("start-btn"); +const message = document.getElementById("message"); +const playerS = document.getElementById("player-s"); +const playerL = document.getElementById("player-l"); +const winner = document.getElementById("winner"); + +// Save the score for both players +let sCount = 0; +let lCount = 0; + +// Check if the game is active +let gameRunning = false; + +// Save the timer +let gameTimeout; + +// Start the game when the button is clicked +startButton.addEventListener("click", function () { + // Read the time from the input + const gameTime = Number(gameTimeInput.value); + + // Check if the time is correct + if (gameTime <= 0 || Number.isNaN(gameTime)) { + message.textContent = "Please enter a valid time greater than 0."; + return; + } + + // Do not start if the game is already running + if (gameRunning) { + message.textContent = "The game is already running."; + return; + } + + // Reset scores + sCount = 0; + lCount = 0; + gameRunning = true; + + // Reset text on the page + playerS.textContent = "S: 0"; + playerL.textContent = "L: 0"; + message.textContent = "Game is running!"; + winner.textContent = ""; + + // Turn off the button during the game + startButton.disabled = true; + + // Stop the game after the chosen time + gameTimeout = setTimeout(function () { + gameRunning = false; + message.textContent = "Time's up!"; + startButton.disabled = false; + + // Check who won + if (sCount > lCount) { + winner.textContent = "Player S wins! 🎉"; + } else if (lCount > sCount) { + winner.textContent = "Player L wins! 🎉"; + } else { + winner.textContent = "It's a draw! 🤝"; + } + }, gameTime * 1000); +}); + +// Listen for keyboard clicks +document.addEventListener("keydown", function (event) { + // Stop if the game is not running + if (!gameRunning) { + return; + } + + // Save the pressed key as a small letter + const keyPressed = event.key.toLowerCase(); + + // Add 1 point if player S presses "s" + if (keyPressed === "s") { + sCount++; + playerS.textContent = "S: " + sCount; + + // Add 1 point if player L presses "l" + } else if (keyPressed === "l") { + lCount++; + playerL.textContent = "L: " + lCount; + } +}); diff --git a/courses/frontend/advanced-javascript/advanced-js-week2/game.exercise/style.css b/courses/frontend/advanced-javascript/advanced-js-week2/game.exercise/style.css new file mode 100644 index 000000000..6b3de26aa --- /dev/null +++ b/courses/frontend/advanced-javascript/advanced-js-week2/game.exercise/style.css @@ -0,0 +1,35 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + text-align: center; + padding-top: 60px; +} + +input, +button { + padding: 10px 14px; + font-size: 16px; + margin: 10px 5px; + border: 1px solid #ccc; + border-radius: 6px; +} + +button { + background-color: #333; + color: white; + cursor: pointer; +} + +button:hover { + background-color: #555; +} + +p { + font-size: 20px; + margin: 12px 0; +} + +#winner { + font-weight: bold; + font-size: 24px; +} diff --git a/courses/frontend/collaboration-via-github/veggies.txt b/courses/frontend/collaboration-via-github/veggies.txt new file mode 100644 index 000000000..701658172 --- /dev/null +++ b/courses/frontend/collaboration-via-github/veggies.txt @@ -0,0 +1,7 @@ +tomato +broccoli +onion +carrot +potato +radish +corn