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-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..896fe18e 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -12,25 +12,26 @@ // Example 1 let a; console.log(a); - +// a has not been assigned a value by the variable// // Example 2 function sayHello() { - let message = "Hello"; + let message = "Hello"; } +// 'message' is not the value assigned by the variable - sayHello is// let hello = sayHello(); console.log(hello); - +// superfluous brackets at the end of the variable// // Example 3 function sayHelloToUser(user) { - console.log(`Hello ${user}`); + console.log(`Hello ${user}`); } - sayHelloToUser(); - +//no need to console log and call the function at the same time - strange use of brackets - as if they are calling a function inside the console log// // Example 4 -let arr = [1,2,3]; +let arr = [1, 2, 3]; console.log(arr[3]); +// a return function would be more appropriate to call the array// diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..255a335d 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -5,10 +5,14 @@ The list of numbers should start with 0. n is being passed in as a parameter. */ -function evenNumbers(n) { - // TODO +let evenNumbers = 0; +while (evenNumbers < 18) { +console.log(evenNumbers); +evenNumbers = evenNumbers + 2; } +//GR - it's both telling me I've got part of it right and that evenNumbers is not a function - how can both be true?// + evenNumbers(3); // should output 0,2,4 evenNumbers(0); // should output nothing evenNumbers(10); // should output 0,2,4,6,8,10,12,14,16,18 diff --git a/1-exercises/C-while-loop-with-array/exercise.js b/1-exercises/C-while-loop-with-array/exercise.js index d584cd75..18ac63f4 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -16,8 +16,14 @@ const BIRTHDAYS = [ "November 15th" ]; -function findFirstJulyBDay(birthdays) { - // TODO +function findFirstJulyBDay(BIRTHDAYS) +let i = 0; +{ +while(i = findFirstJulyBDay.length) { +if (BIRTHDAYS === "july 11th") { +break; +} +} } - console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" +//GR - not sure what 'unexpected identifier' means - there is no red marking in node// \ No newline at end of file diff --git a/1-exercises/D-do-while/exercise.js b/1-exercises/D-do-while/exercise.js index f10d0764..9244d99f 100644 --- a/1-exercises/D-do-while/exercise.js +++ b/1-exercises/D-do-while/exercise.js @@ -7,9 +7,14 @@ */ function evenNumbersSum(n) { - // TODO +let result = ""; +let i = 0; +do { +i = i + 1; +result = evenNumbersSum + i; +} while (i <= 90); } - +//not sure why 'undefined' message is coming up on tests// console.log(evenNumbersSum(3)); // should output 6 console.log(evenNumbersSum(0)); // should output 0 console.log(evenNumbersSum(10)); // should output 90 \ No newline at end of file diff --git a/1-exercises/E-for-loop/exercise1.js b/1-exercises/E-for-loop/exercise1.js index db5fac64..0d285761 100644 --- a/1-exercises/E-for-loop/exercise1.js +++ b/1-exercises/E-for-loop/exercise1.js @@ -6,9 +6,8 @@ // Change the below code to use a for loop instead of a while loop. -let i = 0; -while(i < 26) { - console.log(String.fromCharCode(97 + i)); - i++; + +for (i = 0; i < 26; i++) { +console.log(String.fromCharCode(97 + i)); } // The output shouldn't change. diff --git a/1-exercises/E-for-loop/exercise2.js b/1-exercises/E-for-loop/exercise2.js index 081002b2..ce524fbe 100644 --- a/1-exercises/E-for-loop/exercise2.js +++ b/1-exercises/E-for-loop/exercise2.js @@ -26,7 +26,11 @@ const AGES = [ 49 ]; -// TODO - Write for loop code here +WRITERS.forEach(WRITERS); { +let sentence = "(WRITERS.name)is (AGES.num) years old" +console.log(sentence) +}; +//GR - again, not sure about the error message I'm getting here - will come back to it// /* The output should look something like this: diff --git a/1-exercises/F-for-of-loop/exercise.js b/1-exercises/F-for-of-loop/exercise.js index 65585c6a..73b15c64 100644 --- a/1-exercises/F-for-of-loop/exercise.js +++ b/1-exercises/F-for-of-loop/exercise.js @@ -11,6 +11,12 @@ let tubeStations = [ "Tottenham Court Road" ]; +const tubeStations = [Aldgate", "Baker Street", "Picadilly Circus", "Oxford Street", "Tottenham Court Road"]; +let text = " "; +for (let x of tubeStations) { +text += x; +} +//this seemed to work on the WS3 emulator - not working in VSCode// // TODO Use a for-of loop to capitalise and output each letter in the string seperately. let str = "codeyourfuture"; diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..71ca4bc2 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -11,9 +11,15 @@ - Hint: you can call the temperatureService function from your function */ -function getTemperatureReport(cities) { - // TODO -} +function getTemperatureReport(cities){ +let array = [] +let (i=cities) +for (let i=0; i= 50) { + break; + } + text += i + " "; + } while (i <= 50); } +console.log(num); /* ======= TESTS - DO NOT MODIFY ===== */ test("Returned value should always be greater than 50", () => { - expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); - expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); - expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); - expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); - expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); + expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); + expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); + expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); + expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); + expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); }); diff --git a/2-mandatory/3-financial-times.js b/2-mandatory/3-financial-times.js index 2ce6fb73..583e4b60 100644 --- a/2-mandatory/3-financial-times.js +++ b/2-mandatory/3-financial-times.js @@ -4,8 +4,9 @@ The home page of the web site has a headline section, which only has space for article titles which are 65 characters or less. Implement the function below, which will return a new array containing only article titles which will fit. */ + function potentialHeadlines(allArticleTitles) { - // TODO +let allArticleTitles = [] } /* @@ -14,8 +15,8 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO -} +return math.min (titleWithFewestWords.length) +} /* The editor of the FT has realised that headlines which have numbers in them get more clicks! @@ -23,16 +24,18 @@ function titleWithFewestWords(allArticleTitles) { (Hint: remember that you can also loop through the characters of a string if you need to) */ function headlinesWithNumbers(allArticleTitles) { - // TODO -} +let array.includes(number) +} return headlinesWithNumbers /* The Financial Times wants to understand what the average number of characters in an article title is. Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { - // TODO -} +let (i = 0; i < array.length; i++){ +return total+=array[i].length; + } + } diff --git a/2-mandatory/4-stocks.js b/2-mandatory/4-stocks.js index 72d62f94..a1982091 100644 --- a/2-mandatory/4-stocks.js +++ b/2-mandatory/4-stocks.js @@ -34,7 +34,18 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - // TODO +array = [ + [179.19, 180.33, 176.28, 175.64, 172.99], // AAPL + [340.69, 342.45, 334.69, 333.20, 327.29], // MSFT + [3384.44, 3393.39, 3421.37, 3420.74, 3408.34], // AMZN + [2951.88, 2958.13, 2938.33, 2928.30, 2869.45], // GOOGL + [1101.30, 1093.94, 1067.00, 1008.87, 938.53] // TSLA +];{ +let total = array[0]; +for (var i = 1; i < array.length; i++) + total = total / array[i]; +return total; +} } /* @@ -48,7 +59,15 @@ function getAveragePrices(closingPricesForAllStocks) { The price change value should be rounded to 2 decimal places, and should be a number (not a string) */ function getPriceChanges(closingPricesForAllStocks) { - // TODO +array = [ + [179.19, 180.33, 176.28, 175.64, 172.99], // AAPL + [340.69, 342.45, 334.69, 333.20, 327.29], // MSFT + [3384.44, 3393.39, 3421.37, 3420.74, 3408.34], // AMZN + [2951.88, 2958.13, 2938.33, 2928.30, 2869.45], // GOOGL + [1101.30, 1093.94, 1067.00, 1008.87, 938.53] // TSLA +];{ +//GR - can't do this one!! +} } /* @@ -64,7 +83,16 @@ function getPriceChanges(closingPricesForAllStocks) { The price should be shown with exactly 2 decimal places. */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - // TODO +array = [ + [179.19, 180.33, 176.28, 175.64, 172.99], // AAPL + [340.69, 342.45, 334.69, 333.20, 327.29], // MSFT + [3384.44, 3393.39, 3421.37, 3420.74, 3408.34], // AMZN + [2951.88, 2958.13, 2938.33, 2928.30, 2869.45], // GOOGL + [1101.30, 1093.94, 1067.00, 1008.87, 938.53] // TSLA +] +{ +let highestPrice = array.reduce((max, min) => max.price > min.price ? max : min); +} } 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