Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h1>Prediction Engine</h1>
</div>
<div id="result-section" class="hidden" aria-live="polite">
<p id="result-sentence"></p>
<p id="famous-personalities-sentence"></p>
<button id="try-again-button">Try Again</button>
</div>
</div>
Expand Down
25 changes: 20 additions & 5 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ document.addEventListener('DOMContentLoaded', () => {
const inputSection = document.getElementById('input-section');
const resultSection = document.getElementById('result-section');
const resultSentence = document.getElementById('result-sentence');
const famous_personalities = document.getElementById('famous-personalities-sentence');
const themeToggle = document.getElementById('theme-toggle');

const countryCodes = {
Expand Down Expand Up @@ -273,10 +274,11 @@ document.addEventListener('DOMContentLoaded', () => {

async function fetchPredictions(name) {
try {
const [genderData, ageData, nationalityData] = await Promise.all([
const [genderData, ageData, nationalityData,celebs] = await Promise.all([
fetch(`https://api.genderize.io?name=${name}`).then(response => response.json()),
fetch(`https://api.agify.io?name=${name}`).then(response => response.json()),
fetch(`https://api.nationalize.io?name=${name}`).then(response => response.json())
fetch(`https://api.nationalize.io?name=${name}`).then(response => response.json()),
fetch(`https://api.api-ninjas.com/v1/historicalfigures?name=${name}`, {headers: {'X-Api-Key':'5fEKy/4iO6q+a3r9g9y05g==7pAoJR6AZ2jmo4mW'} }).then(response => response.json()),
]);

const gender = genderData.gender;
Expand All @@ -286,15 +288,28 @@ document.addEventListener('DOMContentLoaded', () => {
const countryCode = nationalityData.country[0]?.country_id || 'Unknown';
const nationality = countryCodes[countryCode] || 'Unknown';
const nationalityProb = nationalityData.country[0] ? (nationalityData.country[0].probability * 100).toFixed(2) + '%' : 'N/A';

displayResults(name, gender, genderProb, age, ageCount, nationality, nationalityProb);
let celebrityNames = celebs.length > 0
? celebs.map(celeb => `<li>${celeb.name} (${celeb.title})</li>`).join('')
: '<li>No famous personalities found.</li>';
displayResults(name, gender, genderProb, age, ageCount, nationality, nationalityProb, celebrityNames);
} catch (error) {
console.error('Error fetching predictions:', error);
}
}

function displayResults(name, gender, genderProb, age, ageCount, nationality, nationalityProb) {
function displayResults(name, gender, genderProb, age, ageCount, nationality, nationalityProb, celebrityNames) {
resultSentence.innerHTML = `Hello ${name}, based on ${ageCount} occurrences, I'm guessing that you are about ${age} years old. There are ${genderProb} chances that you are a ${gender}, and about ${nationalityProb} chances you live in ${nationality}.`;
if (!celebrityNames || celebrityNames.length === 0) {
famous_personalities.innerHTML = `<p>We couldn't find any famous personalities with the same name.</p>`;
} else {
famous_personalities.innerHTML = `
<p>Famous Personalities with the same name:</p>
<ul class="famous-list">
${celebrityNames}
</ul>
`;
}


fadeOut(inputSection, () => {
inputSection.classList.add('hidden');
Expand Down
35 changes: 35 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ body.dark input[type="text"] {
color: white;
}

body.dark ul {
background-color: #444;
border: 2px solid #666;
color: white;
}
body.dark ul li {
color: white;
}
body.dark #famous-personalities-sentence {
color: white;
}

header {
position: fixed;
top: 0;
Expand Down Expand Up @@ -183,4 +195,27 @@ body.dark footer a {
.icon img {
max-width: 150px;
height: auto;
}

#famous-personalities-sentence {
margin-top: 20px;
font-family: Arial, sans-serif;
color: #333;
}

.famous-list {
list-style-type: none;
padding:0px;
margin: 0px ;
}

.famous-list li {
margin-bottom: 8px;
font-size: 16px;
color: #555;
}

.famous-list li:hover {
color: #007BFF;
cursor: pointer;
}