pull/834/merge
Gideon Buba 9 months ago committed by GitHub
commit e052cd5724
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,6 @@
// Use the typeof operator to check data types
console.log(typeof name);
console.log(typeof isStudent);
console.log(typeof age);
console.log(typeof favoriteColor);

@ -13,6 +13,7 @@
<script src="./introduction.js"></script>
<script src="./variable.js"></script>
<script src="./main.js"></script>
<script src="datatypes.js"></script>
</body>

@ -1 +1,3 @@
console.log('Welcome to 30DaysOfJavaScript')
console.log('Welcome to 30DaysOfJavaScript')
//comments can make code readable

@ -1,4 +1,11 @@
// the variable values can be accessed from other variable.js file
/*
console.log(firstName, lastName, country, city, age, isMarried)
console.log(gravity, boilingPoint, PI) // 9.81, 100, 3.14
console.log(name, job, live)
console.log(name, job, live)
*/
//welcome to 30DaysofJavaScript
/* comments can make code readable
easy to reuse and informative
*/

@ -1,20 +1,48 @@
// Declaring different variables of different data types
// Declare and assign string data type
const name = 'Gideon';
let firstName = 'Asabeneh' // first name of a person
let lastName = 'Yetayeh' // last name of a person
let country = 'Finland' // country
let city = 'Helsinki' // capital city
let age = 100 // age in years
let isMarried = true
// Declare and assign boolean data type
const isStudent = true;
// Declaring variables with number values
// Declare a variable without assignment (undefined)
//let age;
const gravity = 9.81 // earth gravity in m/s2
const boilingPoint = 100 // water boiling point, temperature in oC
const PI = 3.14 // geometrical constant
// Declare and assign null data type
const favoriteColor = null;
// Variables can also be declaring in one line separated by comma
// Declaring four variables without assigning values
let gideon
let asabeneh
let gitHub
let nike
let name = 'Asabeneh', //name of a person
job = 'teacher',
live = 'Finland'
// Declaring four variables with assigned values
let randomName = 'Eren';
let year = 2023;
let month = 'August';
let favoriteFruit = 'apple';
// Declaring variables in multiple lines
/* const firstName = 'Gideon';
const lastName = 'Buba';
let isMarried = True;
let country = 'Nigeria';
const age = 21; */
// Declaring varibles in a signle line
let firstName = 'Gideon', lastName = 'Buba', isMarried = true, age = 21;
//variables to log to browser console
myAge = 21;
yourAge = 30;
console.log('I am', myAge , 'years old');
console.log('I am', yourAge, 'years old');
// Print the variables to the console
console.log('Name:', name);
console.log('Is Student:', isStudent);
console.log('Age:', age);
console.log('Favorite Color:', favoriteColor);

@ -15,3 +15,6 @@ const PI = 3.14 // geometrical constant
let name = 'Asabeneh', //name of a person
job = 'teacher',
live = 'Finland'
// Varibles of different data types from excercises

@ -1 +1,185 @@
// this is your main.js script
// this is your main.js script
//Excercises for Day 2
//Exercise 1
let challenge = '30 Days Of JavaScript';
//Exercise 2
console.log(challenge)
//Exercise 3
console.log(challenge.length)
//Exercise 4
console.log(challenge.toUpperCase())
//Exercise 5
console.log(challenge.toLocaleLowerCase())
//Exercise 6
console.log(challenge.substring(2, 8))
//Exercise 7
console.log(challenge.substring(0, 2))
//Exercise 8
console.log(challenge.includes('Script'))
//Exercise 9
console.log(challenge.split())
//Exercise 10
console.log(challenge.split(' '))
//Exercise 11
let companies = 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon'
console.log(companies.split(','))
//Exercise 12
console.log(challenge.replace('JavaScript', 'Python'))
//Exercise 13
console.log(challenge.charAt(15))
//Exercise 14
console.log(challenge.charCodeAt(8))
//Exercise 15
console.log(challenge.indexOf('a'));
//Exercise 16
console.log(challenge.lastIndexOf('a'));
//Exercise 17
let sentence = 'You cannot end a sentence with because because because is a conjunction';
console.log(sentence.indexOf('because'))
//Exercise 18
console.log(sentence.lastIndexOf('because'))
//Exercise 19
console.log(sentence.search('because'))
//Exercise 20
let whiteSpace = ' 30 days of JavaScript ';
console.log(whiteSpace.trim())
//Exercise 21
console.log(challenge.startsWith('30'))
//Exercise 22
console.log(challenge.endsWith('JavaScript'))
//Exercise 23
console.log(challenge.match())
//Exercise 24
const firstString = '30 Days of ';
const secondString = 'JavaScript';
const mergedString = firstString.concat(secondString);
console.log(mergedString);
//Exercise 25
console.log(challenge.repeat(2))
//Exercise Level 2
//Exercise 1
console.log(`The quote "There is no exercise better for the heart than reaching down and lifting people up." by John Holmes teaches us to help one another.`)
//Exercise 2
console.log("Love is not patronizing and charity isn't about pity, it is about love. Charity and love are the same -- with charity you give love, so don't just give money but reach out your hand instead.")
//Exercise 3
let strNumber = '10';
console.log(parseInt(strNumber));
//Exercise 4
let float = '9.8';
console.log(Math.ceil(float))
//Exercise 5
let word1 = 'Python'
let word2 = 'Jargon'
console.log(word1.includes('on'))
console.log(word2.includes('on'))
//Exercise 6
let word = 'I hope this course is not full of jargon. Check if jargon is in the sentence.'
console.log(word.includes('jargon'))
//Exercise 7
const num = Math.floor(Math.random() * 99);
console.log(num);
//Exercise 8
const min = 50;
const max = 100;
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
console.log(randomNumber);
//Exercise 9
const randNum = Math.floor(Math.random() * 254)
console.log(randNum);
//Exercise 10
let string = 'JavaScript';
let randomIndex = Math.floor((Math.random() * string.length))
console.log(randomIndex)
//Exercise 11
//Exercise 12
let subStr = 'You cannot end a sentence with because because because is a conjunction';
const removedWord = subStr.slice(30, 54)
console.log(removedWord)
// Exercise Level 3
// Exercise 1
let numberOfWords = 'Love is the best thing in this world. Some found their love and some are still looking for their love.';
console.log(numberOfWords.match(/love/gi))
//Exercise 2
let numWords = 'You cannot end a sentence with because because because is a conjunction'
console.log(numWords.match(/because/gi))
//Exercise 3
const expression = "I am a teacher, and I love teaching. There is nothing as more rewarding as educating and empowering people. I found teaching more interesting than any other jobs. Does this motivate you to be a teacher? This 30 Days Of JavaScript is also the result of love of teaching.";
//Exercise 4
// Calculate the total annual income of the person by extracting the numbers from the following text. 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.'
const annualIncome = 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.'
const numberPattern = /\d+/g;
console.log(numberPattern)
const numbers = annualIncome.match(numberPattern);
const monthlySalary = parseInt(numbers[0]);
const annualBonus = parseInt(numbers[1]);
const monthlyCoursesIncome = parseInt(numbers[2]);
const totalAnnualIncome = (monthlySalary * 12) + annualBonus + (monthlyCoursesIncome * 12);
console.log(`Total Annual Income: ${totalAnnualIncome} euro`);

@ -1 +1,213 @@
// this is your main.js script
// this is your main.js script
// Day 3 Exercises
// Exercise Level 1
// Exercise 1
const firstName = 'Gideon';
const lastName = 'Buba';
let country = 'Nigeria';
const age = '23';
let isMarried = false;
let year = 2023;
console.log(typeof(firstName))
console.log(typeof(lastName))
console.log(typeof(country))
console.log(typeof(age))
console.log(typeof(isMarried))
console.log(typeof(year))
// Exercise 2
let string = '10'
let number = 10;
console.log(string === number) //false
// Exercise 3
let decimal = 9.8;
let wholeNumber = 10;
console.log(parseInt(decimal) === wholeNumber);
// Exercise 4
// Truthy value
'true'
'Hello World'
'Gideon'
// Falsy value
'false'
'0'
'null'
// Exercsie 5
//Choices without console.log()
4 > 3 //true
4 >= 3 //true
4 < 3 //false
4 <= 3 //false
4 == 4 //true
4 === 4 //true
4 != 4 //false
4 !== 4 //false
4 != '4' //true
4 == '4' //false
4 === '4' //false
//choices with console.log()
console.log(4 > 3) //true
console.log(4 >= 3) //true
console.log(4 < 3) //false
console.log(4 <= 3) //false
console.log(4 == 4) //true
console.log(4 === 4) //true
console.log(4 != 4) //false
console.log(4 !== 4) //false
console.log(4 != '4') //true
console.log(4 == '4') //true
console.log(4 === '4') //false
let python = 'python';
let jargon = 'jargon';
let pythonLenght = python.length;
let jargonLenght = jargon.length;
console.log(pythonLenght === jargonLenght)
// Exercise 6
//choices without console.log
4 > 3 && 10 < 12 //true
4 > 3 && 10 > 12 //false
4 > 3 || 10 < 12 //true
4 > 3 || 10 > 12 //true
!(4 > 3) //false
!(4 < 3) //true
!(false) //true
!(4 > 3 && 10 < 12) //false
!(4 > 3 && 10 > 12) //true
!(4 === '4') //true
//choices with console.log()
console.log(4 > 3 && 10 < 12)
//true
console.log(4 > 3 && 10 > 12)
//false
console.log(4 > 3 || 10 < 12)
//true
console.log(4 > 3 || 10 > 12)
//true
console.log(!(4 > 3))
//false
console.log(!(4 < 3))
//true
console.log(!(false))
//true
console.log(!(4 > 3 && 10 < 12))
//false
console.log(!(4 > 3 && 10 > 12))
//true
console.log(!(4 === '4'))
//true
// Exercise 7
//todays year
let date = new Date();
console.log(date.getFullYear()) //'2021'
//todays month
console.log(date.getMonth()) //'8' (January is zero, so December has a value of one less than January.)
//todays date
console.log(date.getDate()) //'9'
//todays day
console.log(date.getDay()) //'5'
//hour as of now
console.log(date.getHours()) //'8'
//minute as of now
console.log(date.getMinutes()) //'6'
//seconds from January 1, 1970 to now
// Exercise Level 2
// Exercise 1
let base = prompt('Enter base of the triangle: ')
let height = prompt('Enter height of the triangle: ')
let area = 0.5 * base * height
console.log(`The area of the triangle is ${area}: `)
// Exercise 2
let sideA = prompt('Enter side a:')
let sideB = prompt('Enter side b:')
let sideC = prompt('Enter side c:')
let perimiter = sideA + sideB + sideC
console.log(`The perimeter of a triangle is ${perimiter}`)
//Exercise 3
let length = prompt('Enter lenght:')
let width = prompt('Enter Width:')
let perimeterOfRectangle = 2 * (length * width)
let areaOfRectangle = length * width * perimeterOfRectangle
console.log(`The area of the rectangle is ${areaOfRectangle}`)
// Exercise 4
let radius = prompt('Enter radius of the circle:')
let pi = Math.PI
let areaOfCircle = pi * radius * radius
let circumference = 2 * pi * radius
console.log(`The area of the circle is ${area}: `);
console.log(`The circumfrence of the circle is ${circumference}: `);
// Exercise 5
const slope = 2;
const xIntercept = 1;
const yIntercept = -2;
console.log(`Slope: ${slope}`);
console.log(`X-Intercept: ${xIntercept}`);
console.log(`Y-Intercept: ${yIntercept}`);
// Exercise 6
const x1 = 2;
const y1 = 2;
const x2 = 6;
const y2 = 10;
const slope2 = (y2 - y1) / (x2 - x1);
console.log("The slope between the points is:", slope);
// Exercise 7
// Exercise 8

Loading…
Cancel
Save