-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
97 lines (84 loc) · 2.44 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
window.addEventListener('load', function () {
const projects = [
{
title: 'Project 1',
description: 'A responsive website for a local business.',
imageUrl: 'https://via.placeholder.com/150/0000FF/808080?Text=Placeholder',
},
{
title: 'Project 2',
description: 'A single-page web app using React.js.',
imageUrl: 'https://via.placeholder.com/150/0000FF/808080?Text=Placeholder',
},
{
title: 'Project 3',
description: 'A blog site built with Jekyll and GitHub Pages.',
imageUrl: 'https://via.placeholder.com/150/0000FF/808080?Text=Placeholder',
},
];
const projectsContainer = document.querySelector('.projects-container');
projects.forEach((project) => {
const projectCard = document.createElement('div');
projectCard.classList.add('project-card');
projectCard.innerHTML = `
<h4>${project.title}</h4>
<img src="${project.imageUrl}" alt="${project.title}">
<p>${project.description}</p>
`;
projectsContainer.appendChild(projectCard);
});
});
// ... existing code ...
function navigateTo(hash) {
const sections = document.querySelectorAll("section");
sections.forEach((section) => {
if (section.id === hash) {
section.classList.add("active");
} else {
section.classList.remove("active");
}
});
}
function handleHashChange() {
const hash = location.hash.substring(1);
navigateTo(hash);
}
window.addEventListener("load", function () {
// Populate projects
// ... existing code ...
// Set up routing
window.addEventListener("hashchange", handleHashChange);
if (location.hash) {
handleHashChange();
} else {
location.hash = "#about";
}
});
function bmiCalculator(weight, height) {
let bmi = weight / (height * height);
bmi = Math.round(bmi);
let message;
if (bmi < 18.5) {
message = "Your BMI is " + bmi + ", so you are underweight.";
} else if (bmi >= 18.5 && bmi <= 24.9) {
message = "Your BMI is " + bmi + ", so you have a normal weight.";
} else if (bmi > 24.9) {
message = "Your BMI is " + bmi + ", so you are overweight.";
}
return message;
}
function isLeap(year) {
if (year % 4 === 0) {
if (year % 100 === 0) {
if (year % 400 === 0) {
return "Leap year.";
} else {
return "Not leap year.";
}
} else {
return "Leap year.";
}
} else {
return "Not leap year.";
}
}