diff --git a/.replit b/.replit new file mode 100644 index 00000000..b0123cfa --- /dev/null +++ b/.replit @@ -0,0 +1,75 @@ + +hidden = [".config"] +run = "npm run start" + +[[hints]] +regex = "Error \\[ERR_REQUIRE_ESM\\]" +message = "We see that you are using require(...) inside your code. We currently do not support this syntax. Please use 'import' instead when using external modules. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)" + +[nix] +channel = "stable-21_11" + +[env] +XDG_CONFIG_HOME = "/home/runner/.config" +PATH = "/home/runner/$REPL_SLUG/.config/npm/node_global/bin:/home/runner/$REPL_SLUG/node_modules/.bin" +npm_config_prefix = "/home/runner/$REPL_SLUG/.config/npm/node_global" + +[gitHubImport] +requiredFiles = [".replit", "replit.nix", ".config"] + +[packager] +language = "nodejs" + + [packager.features] + packageSearch = true + guessImports = true + enabledForHosting = false + +[unitTest] +language = "nodejs" + +[languages.javascript] +pattern = "**/{*.js,*.jsx,*.ts,*.tsx}" + + [languages.javascript.languageServer] + start = [ "typescript-language-server", "--stdio" ] + +[debugger] +support = true + + [debugger.interactive] + transport = "localhost:0" + startCommand = [ "dap-node" ] + + [debugger.interactive.initializeMessage] + command = "initialize" + type = "request" + + [debugger.interactive.initializeMessage.arguments] + clientID = "replit" + clientName = "replit.com" + columnsStartAt1 = true + linesStartAt1 = true + locale = "en-us" + pathFormat = "path" + supportsInvalidatedEvent = true + supportsProgressReporting = true + supportsRunInTerminalRequest = true + supportsVariablePaging = true + supportsVariableType = true + + [debugger.interactive.launchMessage] + command = "launch" + type = "request" + + [debugger.interactive.launchMessage.arguments] + args = [] + console = "externalTerminal" + cwd = "." + environment = [] + pauseForSourceMap = false + program = "./index.js" + request = "launch" + sourceMaps = true + stopOnEntry = false + type = "pwa-node" diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..fb47995f 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -5,10 +5,10 @@ */ let dog = { - breed: "Dalmatian", - name: "Spot", - isHungry: true, - happiness: 6 + breed: "Dalmatian", //string + name: "Spot", //string + isHungry: true, //Boolean + happiness: 6 //number }; /* @@ -16,8 +16,8 @@ let dog = { Log the name and breed of this dog using dot notation. */ -let dogName; // complete the code -let dogBreed; // complete the code +let dogName = "Spot" +let dogBreed = "Dalmation" console.log(`${dogName} is a ${dogBreed}`); diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index 5b523ace..978265de 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -17,7 +17,7 @@ let capitalCities = { */ let myCountry = "UnitedKingdom"; -let myCapitalCity; // complete the code +let myCapitalCity = "London" console.log(myCapitalCity); diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 2e160dd5..b0d92e98 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -20,8 +20,10 @@ let basketballTeam = { - console.logs the name of each player on a new line */ -// write code here +let topPlayers = ["Michael Jordan", "Scottie Pippen", "Dennis Rodman"]; +topPlayers.sort(); +console.log(topPlayers); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..898f98a9 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -3,15 +3,23 @@ You can also change the value assigned to a property using dot notation. */ -let capitalCities = { - UnitedKingdom: { - name: "London", - population: 20, - }, - China: { - name: "Beijing", - } -}; +// let capitalCities = { +// UnitedKingdom: { +// name: "London", +// population: 20, +// }, +// China: { +// name: "Beijing", +// population: 21500000, +// } +// Peru: { +// name: "Lima" +// population: 9750000, +// } +// }; + + + /* Using dot notation: @@ -24,8 +32,24 @@ let capitalCities = { // write code here +let capitalCities = { + UnitedKingdom: { + name: "London", + population: 20, + }, + China: { + name: "Beijing", + population: 21500000, + }, +Peru: { + name: "Lima", + population: 9750000, +} +}; +capitalCities.UnitedKingdom = 8980000; console.log(capitalCities); + /* EXPECTED RESULT { diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..1783df59 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -3,11 +3,7 @@ You can also change the value assigned to a property using bracket notation. */ -let student = { - name: "Reshma Saujani", - examScore: 65, - hasPassed: false -}; + /* Using bracket notation @@ -27,6 +23,13 @@ let student = { // write code here +let student = { +name: "Reshma Saujani", +examScore: 65, +hasPassed: true, +attendance: 90, +}; + console.log(student); /* EXPECTED RESULT diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..fb88adbb 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -14,7 +14,7 @@ let car = { yearsOld: 8, }; -console.log(car["colour"]); +console.log(car["colour"]); //"colour" is not defined as an object anywhere in the variable statement// // Example 2 function sayHelloToUser(user) { @@ -25,7 +25,7 @@ let user = { name: "Mira" }; -sayHelloToUser(user); +sayHelloToUser(user); //Hello in the console log is undefined, as well as 'firstName' not identified as the object 'name'// // Example 3 let myPet = { @@ -35,4 +35,4 @@ let myPet = { }, }; -console.log(myPet.getName()); +console.log(myPet.getName()); //has attempted to create a function element where the property should be// diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..5713edbe 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -8,10 +8,13 @@ */ let student = { - // write code here -} + name: "Daniel", + message: function () { + return "Student name: + (name) "; + }, +}; -student.getName("Daniel"); +console.log (student) /* EXPECTED RESULT diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..58d0205d 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,38 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +let recipe1 = { +name: "Pepperoni Pizza", +serves: 3, +ingredients: ["bread", "tomato sauce", "pepperoni", "cheese"], +} + +let recipe2 = { +name: "chilli con carne", +serves: 5, +ingredients: ["beef", "chillies", "tomato sauce", "kidney beans"], +} + +let recipe3 = { +name: "Kung Pao Chicken", +serves: 2, +ingredients: ["chicken", "peanuts", "soy sauce", "beansprouts"], +} + +let recipe4 = { +name: "Indian Mixed Grill", +serves: 5, +ingredients: ["tandori chicken", "pork chops", "bell peppers", "chillies"], +} + +let recipe5 = { +name: "Full English Breakfast", +serves: 1, +ingredients: ["bacon", "sausage", "fried egg", "baked beans"], +} + +console.log(recipe1) +console.log(recipe2) +console.log(recipe3) +console.log(recipe4) +console.log(recipe5) \ No newline at end of file diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..3f163305 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,8 +18,14 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here -} +let currencyCodes = {}; +countryCurrencyCodes.forEach((element) => +currencyCodes[0] = element[1] +) +return currencyCodes +}; + + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..1acc6967 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -18,8 +18,11 @@ let pantry = { cupboardContents: ["salt", "tinned tomatoes", "oregano"], }; + function createShoppingList(recipe) { - // write code here +let allItems = pantry.fridgeContents.concat(pantry.cupboardContents); +(ingredients) => combinedPantry.includes(ingredients); +return allItems; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..30256a21 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,7 +20,10 @@ const MENU = { }; let cashRegister = { - // write code here +orderBurger: function (balance){ +(balance >= MENU.burger) +return (balance = balance - MENU.burger); +} } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/replit.nix b/replit.nix new file mode 100644 index 00000000..9d433375 --- /dev/null +++ b/replit.nix @@ -0,0 +1,8 @@ +{ pkgs }: { + deps = [ + pkgs.nodejs-16_x + pkgs.nodePackages.typescript-language-server + pkgs.yarn + pkgs.replitPackages.jest + ]; +} \ No newline at end of file