Skip to content

Anica Rahman - JS Fundamentals#37

Open
Anicaaa wants to merge 29 commits intoboolean-uk:mainfrom
Anicaaa:main
Open

Anica Rahman - JS Fundamentals#37
Anicaaa wants to merge 29 commits intoboolean-uk:mainfrom
Anicaaa:main

Conversation

@Anicaaa
Copy link

@Anicaaa Anicaaa commented Mar 7, 2022

No description provided.


// TODO: write code in this function body to pass the tests

if (true) alert('Well done, you passed!')
Copy link
Contributor

Choose a reason for hiding this comment

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

the function is asking to check if the value that has been passed to the getResult function is true or false, and return a different string.

if(didPass === true) {
   return "Well done, you passed!"
}

function isArrayEmpty (array) {

// TODO: write code in this function body to pass the tests
if (array === []) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what you have coded will work; you can also choose to do the following:

if(array.length === 0) to test if the array is empty


// Set fourthCity to the 4th element in the cities array
const fourthCity = ''
const fourthCity = 'Delhi'
Copy link
Contributor

Choose a reason for hiding this comment

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

the exercise here is asking you to set fourthCity to the 4th element of the cities array.

The elements of an array are numbered from 0 onwards, with 0 being the first element, 1 being the second. Hence the 4th element has an index of 3.

I can then do the following: fourthCity = cities[3] which means, take the 3rd element in the cities list and assign it to the variable called fourthCity


// Set firstCity to the 1st element in the cities array
const firstCity = ''
const firstCity = 'London'
Copy link
Contributor

Choose a reason for hiding this comment

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

same as the comment above


// Use an array method to remove the first item from colours
colours
colours.shift('Red')
Copy link
Contributor

Choose a reason for hiding this comment

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

shift() can be called without an argument (value) and that will remove the first item, see the documentation here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift


// Use an array method to remove the last item from keys
keys
keys.pop('y')
Copy link
Contributor

Choose a reason for hiding this comment

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

the pop() function of an array does not need an argument, it will simply remove the last item

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop


// Set this variable to numOne added to numTwo
const numOnePlusNumTwo = NaN
const numOnePlusNumTwo = 8 + 16
Copy link
Contributor

Choose a reason for hiding this comment

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

can you re-write the solutions below to use the variables at the start of the file?

for example: const numOnePlusNumTwo = numOne + numTwo

}
const computer = {
form: 'laptop',
specs: (
Copy link
Contributor

Choose a reason for hiding this comment

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

there should not be an ( and ) brackets here. To define an object i just need { ... }, so specs should be:


basket.items[0].price = 2

basket.items[2] = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

there's no need for ( and ); to add an object you need to:

  1. define the object with the { } syntax and
  2. call push on the array:
baseket.items.push({...})

// TODO: Write a for loop that adds all the even numbers between 0 and 6 (0, 2, 4, 6) to evenNums
const numbers = [0, 2, 4, 6];
for (let i = 0; i < numbers.length; i++) {
if (numbers[i]) 2 === 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

this if statement won't work: you will need to place all the comparison instruction inside the ():

if(numbers[i] % 2 === 0) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants