Skip to content

Commit

Permalink
Refactor hoursToSeconds function and improve input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nolecram committed Dec 5, 2024
1 parent 1118f12 commit f35c077
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Hello World.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@

// Function to convert hours to seconds
function hoursToSeconds(hours) {
return hours * 3600;
}
const hoursToSeconds = hours => hours * 3600;

// Implement input and output functionality
// Read an input value for hours
const hoursInput = prompt("Enter time in hours:");

// Convert the input value to a number
const hours = parseFloat(hoursInput);
// Convert the input value to a number and check if it's valid
const hours = Number(hoursInput);

// Check if the input is a valid number
if (isNaN(hours)) {
alert("Please enter a valid number.");
} else {
Expand All @@ -20,4 +16,4 @@ if (isNaN(hours)) {

// Display the converted seconds value
alert(`Time in seconds: ${seconds}`);
}
}

0 comments on commit f35c077

Please sign in to comment.