Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code #433

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function bmi(mass, height) {
return mass / height ** 2;
}
console.log(bmi(78, 1.69));
console.log("Break\nBreak\nBreak");
let mark = {
mass: 78,
height: 1.69,
bmi: function () {
return (bmi = this.mass / this.height ** 2);
},
};
console.log(mark.bmi());

let john = {
mass: 92,
height: 1.95,
bmi: function () {
return (bmi = this.mass / this.height ** 2);
},
};
console.log(john.bmi());

let markHigherBMI = mark.bmi() > john.bmi();
console.log(markHigherBMI);

module.exports = bmi;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* function bmi(mass, height) {
return mass / height ** 2;
}
console.log(bmi(78, 1.69));
console.log("Break\nBreak\nBreak");
*/
let mark = {
name: "Mark",
mass: 78,
height: 1.69,
bmi: function () {
bmi = this.mass / this.height ** 2;
return bmi.toFixed(2);
},
};

let john = {
name: "John",
mass: 92,
height: 1.95,
bmi: function () {
bmi = this.mass / this.height ** 2;
return bmi.toFixed(2);
},
};

if (mark.bmi() > john.bmi()) {
return console.log(
`${mark.name}'s BMI (${mark.bmi()}) is higher than ${
john.name
}'s (${john.bmi()})!`
);
} else if (john.bmi() > mark.bmi()) {
return console.log(
`${john.name}'s BMI (${john.bmi()}) is higher than ${
mark.name
}'s (${mark.bmi()})!`
);
}

module.exports = bmi;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class person {
constructor(name, mass, height) {
this.name = name;
this.mass = mass;
this.height = height;
}
bmi = function () {
return Math.round((this.mass / this.height ** 2) * 100) / 100;
};
}

let mark = new person("Mark", 78, 1.69);
let john = new person("John", 92, 1.95);

if (mark.bmi() > john.bmi()) {
return console.log(
`${mark.name}'s BMI (${mark.bmi()}) is higher than ${
john.name
}'s (${john.bmi()})!`
);
} else if (john.bmi() > mark.bmi()) {
return console.log(
`${john.name}'s BMI (${john.bmi()}) is higher than ${
mark.name
}'s (${mark.bmi()})!`
);
}

module.exports = person;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const person = require("../codingChallenge_2_1.js");

describe("BMI Function", function () {
test("deviding weight by 2 times the height,", function () {
let mark = new person("Mark", 78, 1.69);
expect(mark.bmi()).toEqual(27.31);
});
test("if statement", function () {
let mark = new person("Mark", 78, 1.69);
let john = new person("John", 92, 1.95);
expect(mark.bmi() > john.bmi()).toEqual(27.31 > 24.19);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>JavaScript Fundamentals – Part 1</title>
<style>
body {
height: 100vh;
display: flex;
align-items: center;
background: linear-gradient(to top left, #28b487, #7dd56f);
}
h1 {
font-family: sans-serif;
font-size: 50px;
line-height: 1.3;
width: 100%;
padding: 30px;
text-align: center;
color: white;
}
</style>
</head>
<body>
<h1>JavaScript Fundamentals – Part 1</h1>

<script src="scriptAssignment.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function bmi(mass, height) {
return mass / height ** 2;
}

console.log(bmi(78, 1.69));
console.log("Break\nBreak\nBreak");
let mark = {
mass: 78,
height: 1.69,
bmi: function () {
return (bmi = this.mass / this.height ** 2);
},
};
console.log(mark.bmi());

let john = {
mass: 92,
height: 1.95,
bmi: function () {
return (bmi = this.mass / this.height ** 2);
},
};
console.log(john.bmi());

let markHigherBMI = mark.bmi() > john.bmi();
console.log(markHigherBMI);

module.exports = bmi;
4 changes: 3 additions & 1 deletion 01-Fundamentals-Part-1/starter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
</head>
<body>
<h1>JavaScript Fundamentals – Part 1</h1>

<script src="script.js"></script>
</body>
</html>
</html>
119 changes: 119 additions & 0 deletions 01-Fundamentals-Part-1/starter/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* let js = 'amazing';
console.log(40+8+23-10);

console.log("Jonas");
console.log('23');


let firstName = "Jonas";
let firstNamePerson;
let first_name_person;

console.log(firstName);
console.log(firstName);
console.log(firstName);

let threeyears = 3;
console.log(threeyears);

console.log(Math.PI);

let myFIrstJob = "Programmer";
let myCurrentJob ='Teacher';

console.log(myCurrentJob);
console.log('BREAAAAAAAK\n',10)


let country = 'USA';
let continent = 'NA';
let population = 100;

console.log(country);
console.log(continent);
console.log(population);
console.log('BREAAAAAAAK\n',10)


let myCountry = function(countryy){
if (country === 'USA'){
return console.log(true);
}};
myCountry('USA');
let javascriptIsFun = false;
console.log(typeof javascriptIsFun);

javascriptIsFun = String(10);
console.log(javascriptIsFun);
console.log(typeof javascriptIsFun);

let undie;
console.log(undie);
console.log(typeof undie);

undie = 'defined';
console.log(undie);
console.log(typeof undie);
console.log(typeof null); */

/* const hammer = "HAMMMERRR";
console.log(hammer);

var job = "programmer";
job = "teacher";
console.log(job);

lastName = "Hesse";
console.log(lastName);
*/

/* const currentYear = 2024;
const agePhil = currentYear - 1995;
const ageEmily = currentYear - 1993;
console.log(currentYear - 1995 > currentYear - 1993);

let x, y;
x = y = 25 - 10 - 5;
console.log(x, y);
*/

/* const day = "friday";
switch (day) {
case "monday":
console.log("plan course structure");
console.log("Go to coding meetup");
break;
case "tuesday":
console.log("Prepare theory videos");
break;
case "wdnesday":
case "thursday":
console.log("Write code examples");
case "friday":
console.log("Record videos");
break;
case "saturday":
case "sunday":
console.log("Enjoy the weekend!");
break;
default:
console.log("Not a valid day!");
}
*/

const age = 23;
age >= 18 ? console.log("beer time") : console.log("water time");

const drink = age >= 18 ? "beer time" : "water time";
console.log(`I like to drink ${drink}`);

const bill = 275;

/* Write your code below. Good luck! 🙂 */
let tip = bill > 50 && bill < 300 ? bill * 0.15 : bill * 0.2;

totalValue = bill + tip;

console.log(
`The Bill was ${bill}, the tip was ${tip} and the total value was ${totalValue}.`
);
30 changes: 30 additions & 0 deletions 02-Fundamentals-Part-2/Phil_work/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>JavaScript Fundamentals – Part 2</title>
<style>
body {
height: 100vh;
display: flex;
align-items: center;
background: linear-gradient(to top left, #28b487, #7dd56f);
}
h1 {
font-family: sans-serif;
font-size: 50px;
line-height: 1.3;
width: 100%;
padding: 30px;
text-align: center;
color: white;
}
</style>
</head>
<body>
<h1>JavaScript Fundamentals – Part 2</h1>
<script src="script.js"></script>
</body>
</html>
Loading