Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-u committed Dec 2, 2023
0 parents commit 7649613
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Configuration for probot-stale - https://github.com/probot/stale

# Number of days of inactivity before an Issue or Pull Request becomes stale
daysUntilStale: 21

# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
exemptLabels:
- bug
- enhancement

# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
# onlyLabels:
# - TestLabel

# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
daysUntilClose: 7

# Label to use when marking as stale
staleLabel: stale

# Comment to post when marking as stale. Set to `false` to disable
markComment: >
This pull request has been automatically marked as stale because it didn't have any recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
closeComment: >
This pull request is closed. Thank you.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Automated Testing
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Load code
uses: actions/checkout@v2
- name: Prepare environment
uses: actions/setup-node@v2
with:
node-version: '14'
check-latest: true
- name: Install dependencies
run: npm i
- name: Run tests
run: npm run test -- --ci --reporters=default --reporters=jest-junit
- name: Reports the results of tests
uses: IgnusG/[email protected]
if: always()
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
run-name: test
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.DS_Store
.vscode
package-lock.json
yarn.lock
*.log
lab-solution.html
228 changes: 228 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png)

# LAB | JS Technical Challenges


<details>
<summary>
<h2>Learning Goals</h2>
</summary>

This exercise allows you to practice and apply the concepts and techniques taught in class.

Upon completion of this exercise, you will be able to:

- Determine correctly the variable scope and hoisting in JavaScript code,
- Interpret correctly how hoisting affects the variables and functions in JavaScript code,
- Determine how variable shadowing affects the variables in JavaScript,
- Interpret correctly how primitive values are passed and compared in JavaScript,
- Interpret correctly how objects and arrays are passed and compared in JavaScript,
- Interpret correctly how function parameters behave in JavaScript,

<br>
<hr>

</details>

## Introduction

Are you ready to put your coding skills to the test? In this exercise, you will be given a series of short code challenges that simulate the types of questions you may encounter during a Junior Developer job interviews or technical assessments. The challenges are designed to help you practice and reflect on the concepts of scope, hoisting, variable shadowing, and passing value versus passing reference. By examining the code and trying to predict the output, you will put your problem-solving skills to the test and gain a better understanding of how these concepts work in JavaScript.

<br>

## Requirements

- Fork this repo.
- Clone this repo.

<br>

## Submission

- Upon completion, run the following commands:

```bash
git add .
git commit -m "Solved lab"
git push origin master
```

- Create a Pull Request and submit your assignment

<br>



## Instructions

We encourage you to try to solve the challenges without running the code first. Once you have written down your answer for a challenge, run the code and check if your answer was correct. If your answer was incorrect, try to understand why the code behaves the way it does.

<br>

You should record your answers in the `answers.md` file and provide a brief explanation for each answer. For example:

```text
1. Challenge 1:
- Answer: a
- Explanation: The output of the code will be "123" because...
```

<br>

### Challenge 1

```javascript
// Challenge 1
let foo = "abc";

function bar() {
foo = "xyz";
console.log(foo);
}

bar();


console.log(foo);
```

<br>

Given the code above, answer the following questions:

1. Which of the following will be the output of the above code? Why?
<br>a) `"abc"` and `"xyz"`
<br>b) `"xyz"` and `"xyz"`
<br>c) `undefined` and `"xyz"`
<br>d) ReferenceError: foo is not defined


<br>

Once you write down your answer, run the code above and check if it is correct.


<br>

### Challenge 2

```javascript
// Challenge 2
let a = 1;

function example(a) {
a = 10;
console.log(a); // Console log 1
}

example(a);


console.log(a); // Console log 2
```

<br>

Given the code above, without running the code, answer the following question:

1. Which of the following will be the output of the above code? Why?
<br>a) `10` and `10`
<br>b) `1` and `10`
<br>c) `10` and `1`
<br>d) ReferenceError: a is not defined


<br>

Once you write down your answer, run the code above and check if it is correct.

<br>

### Challenge 3

```javascript
// Challenge 3

sayHi();

function sayHi() {
console.log("Hi there!");
}
```

<br>

Given the code above, without running the code, answer the following question:
1. What will be the output of the code above? Why?
<br>a) `ReferenceError: sayHi is not defined`
<br>b) `undefined`
<br>c) `"Hi there!"`
<br>d) `TypeError: sayHi is not a function`

<br>

Once you write down your answer, run the code above and check if your answer was correct.


<br>

### Challenge 4

```javascript
const a = { num: 42 };
const b = a;

b.num = 90;

console.log(a);
```

<br>

Given the code above, without running the code, answer the following question:
1. What will be the output of the code above? Why?
<br>a) TypeError: Assignment to constant variable.
<br>b) `{ num: 42 }`
<br>c) `{ num: 90 }`
<br>d) ReferenceError: a is not defined


<br>

Once you write down your answer, run the code above and check if your answer was correct.


<br>

### Bonus: Challenge 5 | Two Rabbits and a Magic Hat :rabbit: :rabbit2: :tophat:

```javascript
function magicHat(obj) {
obj.age = 10;
obj = { name: "Ada", age: 20 };
return obj;
}

const rabbit1 = { name: "Bob", age: 30 };

const rabbit2 = magicHat(rabbit1);

console.log('rabbit1: ', rabbit1);
console.log('rabbit2: ', rabbit2);
```

<br>

Given the code above, without running the code, answer the following question:
1. What will be the output of the code above? Why?
<br>a) `{ name: "Bob", age: 30 }` and `{ name: "Ada", age: 20 }`
<br>b) `{ name: "Bob", age: 30 }` and `{ name: "Bob", age: 10 }`
<br>c) `{ name: "Bob", age: 10 }` and `{ name: "Ada", age: 20 }`
<br>d) ReferenceError: obj is not defined

<br>

Once you write down your answer, run the code above and check if your answer was correct.


<br>
23 changes: 23 additions & 0 deletions answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
1. Challenge 1:
- Answer:
- Explanation:


2. Challenge 2:
- Answer:
- Explanation:


3. Challenge 3:
- Answer:
- Explanation:


4. Challenge 4:
- Answer:
- Explanation:


5. Bonus - Challenge 5:
- Answer:
- Explanation:

0 comments on commit 7649613

Please sign in to comment.