Skip to content

Instantly share code, notes, and snippets.

View dan046's full-sized avatar
🎯
Focusing, Learning, Practicing

Dan dan046

🎯
Focusing, Learning, Practicing
View GitHub Profile
@dan046
dan046 / showPrimes.js
Created August 2, 2023 08:22
showPrime functions and a fun exercise that shows stars. Utilized nested loops and separate function declarations.
// Prime - Factors are only and itself
// Composite - Can be divided evenly by its factors
// 12 = 1, 2, 3, 4, 6, 12
// 11 = 1, 11 - Prime
// 13 = 1, 13 - Prime
const showPrimes = (limit) => {
for (let number = 2; number <= limit; number++) {
@dan046
dan046 / exercise-calculate-grade.js
Created August 1, 2023 08:35
JavaScript Refresher Exercises
// In this exercise, we want to calculate the grade of a student.
// Calculate the average grade
// If the average is 1-59: F
// 60-69: D
// 70-79: C
// 80-89: B
// 90-100: A
const marks = [80, 80, 50]
@dan046
dan046 / exercise-speedLimit.js
Created July 30, 2023 06:31
Speed Limit Algorithm
// Speed Limit = 70
// If the car is driving under the speed limit, we get an OK message.
// If the car is driving exactly at the speed limit, it's still OK.
// Now, for every 5 kilometers above the speed limit, they're going to get 1 point. Let's say, if I drive 75 km per hour, you get 1 point.
// What if I drive 72 km per hour? Still good. For every 5 km above the speed limit, we should give the driver 1 point.
// Use Math.floor(), we can give a function a floating point number and this will convert that to the greatest integer.
// What if you passed 80 km per hour? The driver should get 2 points.
// Now, what if we drive at 180 km per hour? The driver's license should be suspended.
// If the driver gets more than 12 points, their license should be suspended.
@dan046
dan046 / isLandscape.js
Created July 30, 2023 06:30
// Implement a function that accepts two parameters that would detect if an image is landscape or not.
function isLandscape(width, height) {
return width > height
}
console.log(isLandscape(400, 360))
@dan046
dan046 / exercise-fizzBuzz-algorithm.js
Created July 30, 2023 06:29
// A very popular interview question. fizzBuzz Algorithm. We give it an input and it returns a string. // Rules. If the number that we pass in is divisible by 3, we get the word Fizz. // If the number that we pass is divisible by 5, we get Buzz. // If the number that we pass is divisible by 3 and 5 like 15, we get fizzBuzz. // If the number is n…
const output = fizzBuzz("a")
console.log(output)
function fizzBuzz(input) {
if (typeof input !== "number") return NaN
if (input % 3 === 0 && input % 5 === 0) return "fizzBuzz"
if (input % 3 === 0) return "Fizz"
if (input % 5 === 0) return "Buzz"
return input
}
@dan046
dan046 / control-flow.js
Created July 30, 2023 06:28
Write a function that takes two numbers and returns the maximum of the two.
let number = max(35, 35)
function max(num1, num2) {
return num1 > num2 ? num1 : num2
}
console.log(number)
@dan046
dan046 / exercise2.js
Created July 19, 2023 09:16
SuperSimpleDev Exercise 2 JavaScript Refresher - Numbers and Math
// At a restaurant, you order 1 soup for $10, 3 burgers for $8 each, 1 ice cream for $5.
const soup = 10
const burger = 8
const iceCream = 5
const totalCost = soup + (burger * 3) + iceCream
console.log(totalCost) // Output: $39.00
// You're at a restaurant with 2 friends (3 people in total) and make the same order. Calculate how much each person pays.
totalCost * 3 // Output: $117
// Divided to 3 people, since they ordered the same.
@dan046
dan046 / exercise1.js
Created July 19, 2023 06:22
SuperSimpleDev's JavaScript Tutorial Refresher - Lesson 1 Exercises - JS Basics
// alert('Good Morning')
// alert('Hello, Dan!')
console.log(10 + 5)
console.log(20 - 5)
console.log(2 + 2 - 5)
// document.body.innerHTML("Good Morning!")
// document.body.innerHTML("Good Morning, Dan!")
@dan046
dan046 / objects.js
Last active January 24, 2023 10:01
JavaScript Objects Practice. Loyalty Program
let customer = {
customer_name: "Johnny Manggo",
points: 12300,
cart: [
{
item: "Shampoo",
quantity: 2,
price_$: 3,
},
{
@dan046
dan046 / Sync gh-pages + master branches
Created November 6, 2022 11:55 — forked from mandiwise/Sync gh-pages + master branches
Keep gh-pages up to date with a master branch
// Reference: http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/
$ git add .
$ git status // to see what changes are going to be commited
$ git commit -m 'Some descriptive commit message'
$ git push origin master
$ git checkout gh-pages // go to the gh-pages branch
$ git rebase master // bring gh-pages up to date with master
$ git push origin gh-pages // commit the changes