Created
July 8, 2021 14:35
-
-
Save AbudiMutamba/6a9cad15a5f43507dd43c41d22765a6f to your computer and use it in GitHub Desktop.
Ablestate Corhort 1 javascript session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* array.pop() | |
* Removes the last element in the array and returns it. | |
* It's an example of a normal method because it doesn't take in parameters and it doesn't return a function | |
*/ | |
// const ebikaByaBaganda = new Array( | |
// "Balangira", | |
// "Mamba", | |
// "Nyonyi Nyange", | |
// "Mbongo" | |
// ); | |
const ebikaByaBaganda = [ "Balangira", "Mamba","Nyonyi Nyange", "Mbongo"] | |
const ekikaKyetujemu = ebikaByaBaganda.pop(); | |
const omuwendoGweBikaOmukadde = ebikaByaBaganda.length; | |
console.log(ebikaByaBaganda); | |
console.log(ekikaKyetujemu); | |
console.clear(); | |
let omuwendoGweBikaOmupya = ebikaByaBaganda.push("Ngo", "Mpologoma", "Enjovu", "Nsesnne"); | |
if (omuwendoGweBikaOmupya > omuwendoGweBikaOmukadde){ | |
console.log(omuwendoGweBikaOmupya); | |
} | |
/** | |
* Extracting values from the array | |
*/ | |
//First Element | |
console.log(ebikaByaBaganda[0]); | |
// Last element is at the position of array lenght - 1 | |
const ekikaEkisembyeyo = ebikaByaBaganda[ebikaByaBaganda.length - 1]; | |
console.log(ekikaEkisembyeyo); | |
//Extract 3rd and 4th | |
/** | |
* array.slice(begin[,end]) | |
* Returns the exteacted array based on the begin and end positions | |
* Returns all the elements of the array if position are not provided | |
* Returns all the elements from the beginning position if the end is not specified/ provided | |
*/ | |
if (ebikaByaBaganda.length >= 5) { | |
const ebikaEbiliWakati = ebikaByaBaganda.slice(2,4); | |
if (ebikaEbiliWakati.includes("Mmale")) | |
console.log(ebikaEbiliWakati) | |
} | |
// what if we don't provide the beginning and ending | |
let testWithoutPositons = ebikaByaBaganda.slice(); | |
console.log(testWithoutPositons); | |
// What if we provide the beginning position only | |
let testWithBeginOnly = ebikaByaBaganda.slice(3); | |
console.log(testWithBeginOnly); | |
/** | |
* Replacing elements | |
* array.splice(index, howMany, [element1][,..., elementN]) | |
*/ | |
console.log(ebikaByaBaganda) | |
// let positionOfLastElement = omuwendoGweBikaOmupya - 1; | |
// let whatHasBeenExtracted = ebikaByaBaganda.splice(omuwendoGweBikaOmupya - 1, 1 ); | |
console.log(ebikaByaBaganda); | |
//console.log(whatHasBeenExtracted); | |
let whatHasBeenReplaced = ebikaByaBaganda.splice( | |
omuwendoGweBikaOmupya - 1, | |
1, | |
"Nsenene" | |
); | |
console.log(whatHasBeenReplaced); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Dates | |
* Show today's date and time using Date() | |
*/ | |
console.clear(); | |
console.log(Date()); | |
// getDate() | |
let date = new Date(); | |
const dateToday = date.getDate(); | |
console.log(dateToday); | |
if (dateToday > 3 ) console.log(`${dateToday}th`); | |
const weekDay = date.getDay(); | |
console.log(weekDay); | |
const fullYear = date.getFullYear(); | |
console.log(fullYear); | |
// Calculate age based on year | |
let age = fullYear - 1990; | |
console.log(age); | |
const hour = date.getHours(); | |
console.log(hour); | |
const milliSeconds = date.getMilliseconds(); | |
console.log(milliSeconds); | |
const time = date.getTime(); | |
console.log(time); | |
const timeZoneOffset = date.getTimezoneOffset(); | |
console.log(timeZoneOffset); | |
const dateAfter2Days = date.setDate(10); | |
console.log(dateAfter2Days); | |
// setInterval(() => { | |
// console.log(date.toLocalTimeString()); | |
// }, 1000); | |
let birthDate = new Date("February 24, 1998 23:15:00"); | |
// console.log(speficDate); | |
let birthDay = birthDate.getDay(); | |
console.log(birthDay); | |
let weekDays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; | |
//Output day of the week that the person was born | |
let weekBirthDay = weekDays[birthDay]; | |
console.log(weekBirthDay); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment