Home Blog Project Portfolio Bootcamp Journal More About Me Contact

Week 5

Topics Included: Intermediate JavaScript, MongoDB, MongoDB Atlas

Monday 5th February

To continue our study of JavaScript, we began the week with learning about the call stack. We were given examples of code and asked to work out the order of the call stack. While I found this slightly confusing at first, I was able to accurately break down and order a call stack by the end of the session. We also looked into the difference between global scope, function scope and block scope. Next, we learnt about higher order functions and how they allow us to use more functions, within another function, as parameters. We were given a number of higher order function challenges to complete. It took some trial and error, but I used what I have learnt to create a higher function with arrays (shown below):

A funtion I created that shows what season it is when you input a month.

Tuesday 6th February

On the Tuesday we looked deeper into what can be achieved with MongoDB. I learnt how to query arrays, how to use the query filter (as an alternative to MongoDB Shell) and the use of operators and aggregation processes. Some screenshots of my work are shared below (the second pic shows the use of an operator, in the query filter, to find entries with a stock value greater than or equal to 10).

Searching for information in arrays using MongoDB.
Using an operator in the query filter in MongoDB.

We were also introduced to MongoDB Atlas. I now know how to create a collection in Atlas and how to import data into it.

Wednesday 7th February

Midweek, we learnt about asynchronous JavaScript and how it differs from synchronous JS. This included learning about the efficient handling of data through the use of callback functions, promises, and async and await keywords. We were given example JS code, that contains errors, and asked to correct the mistakes. This involved adding in the use of async and await. As you can see in examples below, the code is linked to another file, named promises.js, which allows the efficient use of promises. In the first two image examples (see below), I corrected code (which included inserting async and await) to identify if a number is or isn't even. The third image shows the code before I edited it.

Identitying if a number is even with async and await.
Identitying if a number is even with async and await example 2.
How the code looked before I corrected it.

We also learnt about object oriented programming (OOP) and its reliance on the concept of classes, subclasses and objects. It is another method that can be used to break up code into smaller, reusable chunks.

Thursday 8th February

On the Thursday, we continued our study of databases and learnt how to connect files in VS Code to Mongo DB Atlas. I was then able to input and make edits to data in Mongo DB Atlas by writing code in VS Code. Also, I can now make queries in VS Code about data stored in Atlas. We were given a project to complete on the subject. Images from my project can be seen below:

Using the insertMany function in VS Code to input data into Mongo DB Atlas.
Here you can see where I used the insertMany function in VS Code to input data into a Mongo DB Atlas database.
The VS Code terminal after inputting the information.
The VS Code terminal showing that I had inserted 6 documents into the Atlas database.
This 6 boardgames now visible as data in Mongo DB Atlas.
Here you can see that the information I had inserted fed through to the Atlas database.
Searching for games with a rating of 4.4 or higher.
This code searches for all games with a rating of 4.4 or higher. It also only shows the title and the price in the terminal.
Terminal results, with only game title and price showing.
Here you can see the titles and prices of the relevant games showing in the terminal.

Friday 9th February

On the Friday, we learnt about using Inquirer in JavaScript. This required the further use of functions and allowed us to create questions that can be answered in the terminal. We used a number of different question types including list, confirm and input. I created some questions of my own, which can be seen below. I also made a very simple game using what I have learnt so far. At one point, I found that the game would not run, so I asked Chat GPT to review the code I had written and look for errors. It turned out that I had put the comparison outside of the asynchronous display function. I also needed to add in lines 18 to 21. I find that, if I write code and need to learn why it isn't working as planned, asking Chat GPT can be a very informative and time saving final step as it provides detailed explanations.

Code which includes a confirm type question
This code includes a confirm type question and requires a yes/no answer.
Code which includes a list type question.
This code includes a list and allows for a list option to be chosen and logged into the terminal (my personal choice would be Japan).
.
.
.
.