Merge db1c799a0f
into 8b41cd49c3
commit
98925f35d0
@ -0,0 +1,110 @@
|
||||
// EXERCISE ARRAY
|
||||
// LEVEL 1
|
||||
const countries = [
|
||||
"Albania",
|
||||
"Bolivia",
|
||||
"Canada",
|
||||
"Denmark",
|
||||
"Ethiopia",
|
||||
"Finland",
|
||||
"Germany",
|
||||
"Hungary",
|
||||
"Ireland",
|
||||
"Japan",
|
||||
"Kenya",
|
||||
];
|
||||
const webTechs = [
|
||||
"HTML",
|
||||
"CSS",
|
||||
"JavaScript",
|
||||
"React",
|
||||
"Redux",
|
||||
"Node",
|
||||
"MongoDB",
|
||||
];
|
||||
|
||||
// 1. Declare empaty array
|
||||
const decArr = Array();
|
||||
// console.log(decArr); // []
|
||||
|
||||
// 2. Declare an array with more than 5 number of elements
|
||||
const fifveArr = ["a", "b", "c", "d", "e", "f"];
|
||||
// console.log(fifveArr); // [ 'a', 'b', 'c', 'd', 'e', 'f' ]
|
||||
|
||||
// 3. Find the length of your array
|
||||
const lengthArr = [1, 2, 3, 4, 5, "b", "a", "y", "u"];
|
||||
// console.log(lengthArr.length); // 9
|
||||
|
||||
// 4. Get the first item, the middle item and the last item of the array
|
||||
const getIndexArr = [1, 2, 3, 4, 5, 6, 7, 8];
|
||||
// console.log(getIndexArr[0]); // first item
|
||||
// console.log(getIndexArr[2]); // middle item but it static
|
||||
// console.log(Math.ceil(getIndexArr.length / 2)); // middle item but dinamis, u can use Math.ceil or Math.floor
|
||||
// console.log(getIndexArr[getIndexArr.length - 1]); // last index item
|
||||
|
||||
// 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
|
||||
const mixedDataTypes = [
|
||||
1,
|
||||
"aku sayang ibu",
|
||||
true,
|
||||
{ ibu: "billie elish", bapak: "khalid" },
|
||||
{ profesi: ["tukang cukur", "penyanyi", "pengembala"] },
|
||||
null,
|
||||
];
|
||||
// console.log(mixedDataTypes.length); // 6
|
||||
|
||||
// 6. Declare an array variable name itCompanies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon
|
||||
|
||||
const itCompanies = [
|
||||
"Facebook",
|
||||
"Google",
|
||||
"Microsoft",
|
||||
"Apple",
|
||||
"IBM",
|
||||
"Oracle",
|
||||
"Amazon",
|
||||
];
|
||||
// 7. Print the array using console.log()
|
||||
// console.log(itCompanies);
|
||||
|
||||
// 8. Print the number of companies in the array
|
||||
// console.log(itCompanies.length); // 7
|
||||
|
||||
// 9. Print the first company, middle and last company
|
||||
// console.log(itCompanies[0]); // Facebook
|
||||
// console.log(itCompanies[Math.floor(itCompanies.length / 2)]); // apple
|
||||
// console.log(itCompanies[itCompanies.length - 1]); // amazon
|
||||
|
||||
// 10. Print out each company
|
||||
// for (let i = 0; i < itCompanies.length; i++) {
|
||||
// const element = itCompanies[i];
|
||||
// console.log(element);
|
||||
// }
|
||||
|
||||
// 11. Change each company name to uppercase one by one and print them out
|
||||
let itCompanies2 = itCompanies.map((x) => x.toUpperCase());
|
||||
// console.log(itCompanies2);
|
||||
// [
|
||||
// 'FACEBOOK',
|
||||
// 'GOOGLE',
|
||||
// 'MICROSOFT',
|
||||
// 'APPLE',
|
||||
// 'IBM',
|
||||
// 'ORACLE',
|
||||
// 'AMAZON'
|
||||
// ]
|
||||
|
||||
// 12. Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies.
|
||||
const sentence = itCompanies.toString();
|
||||
// console.log(`${sentence} are big IT companies` ); // Facebook,Google,Microsoft,Apple,IBM,Oracle,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.
|
||||
// let findItcompanies = itCompanies.indexOf("Oracle");
|
||||
// if (findItcompanies != -1) {
|
||||
// console.log(itCompanies[findItcompanies]);
|
||||
// } else {
|
||||
// console.log("company is not found");
|
||||
// }
|
||||
|
||||
// 14. filter out companies which have more than one 'o' without the filter method
|
||||
|
@ -0,0 +1 @@
|
||||
console.log('MENCOBA MENGULANG JAVASCRIPT DARI AWAL')
|
@ -0,0 +1,173 @@
|
||||
<!--! INLINE SCRIPT -->
|
||||
<!-- <!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>30DaysOfScript:Inline Script</title>
|
||||
</head>
|
||||
<body>
|
||||
<button onclick="alert('Welcome to 30DaysOfJavaScript!')">Click Me</button>
|
||||
</body>
|
||||
</html> -->
|
||||
<!-- INLINE SCRIPT -->
|
||||
|
||||
<!--! INTERNAL SCRIPT -->
|
||||
<!--? Open the browser console to see the output from the console.log() -->
|
||||
<!-- <!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>30DaysOfScript:Internal Script</title>
|
||||
<script>
|
||||
console.log('Welcome to 30DaysOfJavaScript')
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html> -->
|
||||
|
||||
<!-- <!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>30DaysOfScript:Internal Script</title>
|
||||
</head>
|
||||
<body>
|
||||
<button onclick="alert('Welcome to 30DaysOfJavaScript!');">Click Me</button>
|
||||
<script>
|
||||
console.log('Welcome to 30DaysOfJavaScript')
|
||||
</script>
|
||||
</body>
|
||||
</html> -->
|
||||
<!--! INTERNAL SCRIPT -->
|
||||
|
||||
<!--! EXTERNAL SCRIPT -->
|
||||
<!-- HEAD -->
|
||||
|
||||
<!-- <!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>30DaysOfJavaScript:External script</title>
|
||||
<script src="introduction.js"></script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html> -->
|
||||
|
||||
<!-- BODY -->
|
||||
<!--? it could be in the header or in the body // Here is the recommended place -->
|
||||
<!-- <!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>30DaysOfJavaScript:External script</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="introduction.js"></script>
|
||||
</body>
|
||||
</html> -->
|
||||
<!--! EXTERNAL SCRIPT -->
|
||||
|
||||
<!--! MULTIPLE EXTERNAL SCRIPT -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Multiple External Scripts</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- <script src="./introduction.js"></script>
|
||||
<script src="./helloworld.js"></script> -->
|
||||
<h1>halo semua</h1>
|
||||
</body>
|
||||
</html>
|
||||
<!--! MULTIPLE EXTERNAL SCRIPT -->
|
||||
|
||||
<!-- !VARIABLE -->
|
||||
<!-- ADA 3 -->
|
||||
<!-- VAR, LET, CONST -->
|
||||
<!-- KITA MENGGUNAKAN ES6 YAITU LET DAN CONST KARENA LET CONST ADALAH BLOCK SCOPE -->
|
||||
<!--! VARIABLE -->
|
||||
|
||||
<!--! ARRAY -->
|
||||
<!-- array dapat menyimpan multiple value, dan setiap value memilki index -->
|
||||
<!-- array itu paling cocok dipakek buat list -->
|
||||
<script>
|
||||
// syntax
|
||||
// const arr = Array();
|
||||
// or
|
||||
// let arr = new Array()
|
||||
// console.log(arr); // []
|
||||
|
||||
// Umumnya seperti ini
|
||||
const arr = [];
|
||||
// console.log(arr);
|
||||
|
||||
// SEKARANG MENCARI LENGTH
|
||||
// LENGTH ITU PANJANG dari suatu array
|
||||
// kalau binggung sih sebenarnya bisa diitung aja berapa banyak elements dari variable arraynya
|
||||
|
||||
const numbers = [0, 3.14, 9.81, 37, 98.6, 100]; // array of numbers
|
||||
const fruits = ["banana", "orange", "mango", "lemon"]; // array of strings, fruits
|
||||
const vegetables = ["Tomato", "Potato", "Cabbage", "Onion", "Carrot"]; // array of strings, vegetables
|
||||
const animalProducts = ["milk", "meat", "butter", "yoghurt"]; // array of strings, products
|
||||
const webTechs = ["HTML", "CSS", "JS", "React", "Redux", "Node", "MongDB"]; // array of web technologies
|
||||
const countries = ["Finland", "Denmark", "Sweden", "Norway", "Iceland"]; // array of strings, countries
|
||||
|
||||
// Print the array and its length
|
||||
// console.log("Numbers:", numbers);
|
||||
// console.log("Number of numbers:", numbers.length);
|
||||
// console.log("banyak length fruits: ", fruits.length); // lengthnya ada 4, indexnya ada 3 (karena dihitung dari nol)
|
||||
|
||||
// array juga dapat memilki elements/ items dengan tipe data yang berbeda beda
|
||||
// const arr = [
|
||||
// 1,
|
||||
// "aku sayang ibu",
|
||||
// true,
|
||||
// { ibu: "billie elish", bapak: "khalid" },
|
||||
// { profesi: ["tukang cukur", "penyanyi", "pengembala"] },
|
||||
// ];
|
||||
|
||||
// membuat array dengan split
|
||||
let js = "sekarang review ulang javascript";
|
||||
const jadiArr = js.split("");
|
||||
//console.log(jadiArr); // ["s", "e", "k", "a", "r", "a", "n", "g",.....]
|
||||
|
||||
// Acces array
|
||||
const accArr = ["bayu", "ini", "senin", "oke", "?"];
|
||||
// console.log(accArr[2]); // senin
|
||||
|
||||
// Modify array
|
||||
accArr[0] = "toyib";
|
||||
// console.log(accArr); // ["toyib", "ini", "senin", "oke", "?"]
|
||||
|
||||
// METHOD ARRAY
|
||||
// fill
|
||||
const fillArr = Array(5).fill(9);
|
||||
// console.log(fillArr); // [9,9,9,9,9]
|
||||
|
||||
// concat
|
||||
const conArr1 = [1, 2, 3];
|
||||
const conArr2 = [1, 2, 3];
|
||||
const conArr3 = conArr1.concat(conArr2);
|
||||
// console.log(conArr3);// [1, 2, 3, 1, 2, 3]
|
||||
|
||||
// length
|
||||
const lengthArr = [1, 2, 3];
|
||||
// console.log(lengthArr.length); // 3
|
||||
|
||||
// indexOf
|
||||
// console.log(lengthArr.indexOf(3)); // 3 =>mencari index dengan parameter udah ditentukan
|
||||
// console.log(lengthArr.indexOf(4)); // -1 => nilai default karena tidak ada di dalam list array
|
||||
|
||||
// toString
|
||||
console.log(lengthArr.toString()); // 1,2,3 => menjadi string
|
||||
|
||||
// join
|
||||
const webTechs = [
|
||||
"HTML",
|
||||
"CSS",
|
||||
"JavaScript",
|
||||
"React",
|
||||
"Redux",
|
||||
"Node",
|
||||
"MongoDB",
|
||||
]; // List of web technologies
|
||||
|
||||
console.log(webTechs.join()); // "HTML,CSS,JavaScript,React,Redux,Node,MongoDB"
|
||||
console.log(webTechs.join(" # ")); // "HTML # CSS # JavaScript # React # Redux # Node # MongoDB"
|
||||
</script>
|
||||
<!--! ARRAY -->
|
@ -0,0 +1 @@
|
||||
console.log('WELCOME TO MY SOLUTION 30 DAYS REACT')
|
@ -0,0 +1 @@
|
||||
console.log("try");
|
Loading…
Reference in new issue