Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .replit
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 8 additions & 7 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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//
8 changes: 6 additions & 2 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 9 additions & 3 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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//
9 changes: 7 additions & 2 deletions 1-exercises/D-do-while/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 3 additions & 4 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 5 additions & 1 deletion 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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//

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when i run this , it says writers is not defined

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/*
The output should look something like this:
Expand Down
6 changes: 6 additions & 0 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
12 changes: 9 additions & 3 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<cities.length; i++)
{
console.log("The temperature in " + [i] + " is " + " degrees")
}




/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
26 changes: 18 additions & 8 deletions 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@

// This function shouldn't be changed
function generateRandomNumber() {
console.log("Generating number...");
return Math.round(Math.random() * 100);
console.log("Generating number...");
return Math.round(Math.random() * 100);
}

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop
let num = Math.floor(Math.random() * upper) + 1;
return num;
i = 0;
do {
i += 1;
if (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);
});
17 changes: 10 additions & 7 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
}

/*
Expand All @@ -14,25 +15,27 @@ 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!
Implement the function below to return a new array containing all the headlines which contain a number.
(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;
}
}



Expand Down
34 changes: 31 additions & 3 deletions 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/*
Expand All @@ -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!!
}
}

/*
Expand All @@ -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);
}
}


Expand Down
8 changes: 8 additions & 0 deletions replit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ pkgs }: {
deps = [
pkgs.nodejs-16_x
pkgs.nodePackages.typescript-language-server
pkgs.yarn
pkgs.replitPackages.jest
];
}