Merge 3891df6485 into e067490424
commit
8391ac8a9f
@ -1 +1,2 @@
|
|||||||
console.log('Hello, World!')
|
console.log('Hello, World!')
|
||||||
|
//Print something with JS code.
|
||||||
|
|||||||
@ -1 +1,12 @@
|
|||||||
// this is your main.js script
|
// this is your main.js script
|
||||||
|
|
||||||
|
let string = 'JavaScript'
|
||||||
|
let firstLetter = string[0]
|
||||||
|
console.log(firstLetter) // J
|
||||||
|
let secondLetter = string[1] // a
|
||||||
|
let thirdLetter = string[2]
|
||||||
|
let lastLetter = string[9]
|
||||||
|
console.log(lastLetter) // t
|
||||||
|
let lastIndex = string.length - 1
|
||||||
|
console.log(lastIndex) // 9
|
||||||
|
console.log(string[lastIndex]) // t
|
||||||
|
|||||||
@ -1,3 +1,63 @@
|
|||||||
console.log(countries)
|
// //Exercise in Array
|
||||||
alert('Open the browser console whenever you work on JavaScript')
|
// Exercise Level 1
|
||||||
alert('Open the console and check if the countries has been loaded')
|
/**
|
||||||
|
*
|
||||||
|
* ## 💻 Exercise
|
||||||
|
|
||||||
|
### Exercise: Level 1
|
||||||
|
|
||||||
|
```js
|
||||||
|
const countries = [
|
||||||
|
'Albania',
|
||||||
|
'Bolivia',
|
||||||
|
'Canada',
|
||||||
|
'Denmark',
|
||||||
|
'Ethiopia',
|
||||||
|
'Finland',
|
||||||
|
'Germany',
|
||||||
|
'Hungary',
|
||||||
|
'Ireland',
|
||||||
|
'Japan',
|
||||||
|
'Kenya'
|
||||||
|
]
|
||||||
|
|
||||||
|
const webTechs = [
|
||||||
|
'HTML',
|
||||||
|
'CSS',
|
||||||
|
'JavaScript',
|
||||||
|
'React',
|
||||||
|
'Redux',
|
||||||
|
'Node',
|
||||||
|
'MongoDB'
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Declare an _empty_ array;
|
||||||
|
2. Declare an array with more than 5 number of elements
|
||||||
|
3. Find the length of your array
|
||||||
|
4. Get the first item, the middle item and the last item of the array
|
||||||
|
5. Declare an array called _mixedDataTypes_, put different data types in the array and find the length of the array. The array size should be greater than 5
|
||||||
|
6. Declare an array variable name itCompanies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon
|
||||||
|
7. Print the array using _console.log()_
|
||||||
|
8. Print the number of companies in the array
|
||||||
|
9. Print the first company, middle and last company
|
||||||
|
10. Print out each company
|
||||||
|
11. Change each company name to uppercase one by one and print them out
|
||||||
|
12. Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies.
|
||||||
|
13. Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is _not found_
|
||||||
|
14. Filter out companies which have more than one 'o' without the filter method
|
||||||
|
15. Sort the array using _sort()_ method
|
||||||
|
16. Reverse the array using _reverse()_ method
|
||||||
|
17. Slice out the first 3 companies from the array
|
||||||
|
18. Slice out the last 3 companies from the array
|
||||||
|
19. Slice out the middle IT company or companies from the array
|
||||||
|
20. Remove the first IT company from the array
|
||||||
|
21. Remove the middle IT company or companies from the array
|
||||||
|
22. Remove the last IT company from the array
|
||||||
|
23. Remove all IT companies
|
||||||
|
*/
|
||||||
|
//Empty array
|
||||||
|
const animals = ['lion','dog','cat','pig','monkey'];
|
||||||
|
console.log(`This is my array: ${animals}`)
|
||||||
|
const myArrayLength = animals.length;
|
||||||
|
console.log(`This array length is: ${myArrayLength}`);
|
||||||
|
|||||||
Loading…
Reference in new issue