Skip to content

Commit

Permalink
Merge branch 'feature'
Browse files Browse the repository at this point in the history
  • Loading branch information
lee_c committed Feb 25, 2024
2 parents 0cc27eb + 60ec300 commit 672dc89
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
// Global variables //
// Selecting elements from the DOM
var tripInfoButton = document.querySelector(".trip-info");
var dailyBudget = document.querySelector(".daily-budget");

// Uncomment the line below for debugging purposes
//console.log(tripInfoButton, dailyBudget);

// Function to gather trip information
var tripInfo = function () {
// Gathering trip details through user prompts
var totalBudget = Number(prompt("What is your total budget for this trip? "));
var accommodation = Number(prompt("What are your accommodation costs? "));
var transportation = Number(prompt("What are your transportation costs? "));
var numDays = Number(prompt("How many days does your trip last? "));

// Invoking the 'calculateDailyBudget' function with the gathered information
calculateDailyBudget(totalBudget, accommodation, transportation, numDays);
};

// Function to calculate and display budget
var calculateDailyBudget = function (totalBudget, accommodation, transportation, numDays) {
// Calculating the daily budget
var daily = ((totalBudget - accommodation - transportation) / numDays).toFixed(2);

// Updating the content of the 'dailyBudget' element to display the calculated daily budget
dailyBudget.innerText = `You can spend $${daily} a day on food and fun!`;
};

// Event listener for the 'tripInfoButton' to trigger the 'tripInfo' function on button click
tripInfoButton.addEventListener("click", tripInfo);

0 comments on commit 672dc89

Please sign in to comment.