Sure! Here's the optimized and rewritten code:
<!DOCTYPE html>
<html>
<head>
<title>HTML Editor - Full Version</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
font-size: 24px;
margin-bottom: 10px;
}
input[type=text] {
padding: 5px;
border-radius: 5px;
border: 1px solid #ccc;
width: 200px;
}
</style>
<script>
function calculateOriginalPoint() {
const originalPointInput = document.getElementById('original-point-input');
const timeLeftInput = document.getElementById('time-left-input');
const sectionDurationInput = document.getElementById('section-duration-input');
const output = document.getElementById('output');
// Check if all the input fields contain a value
if (originalPointInput.value && timeLeftInput.value && sectionDurationInput.value) {
const [hoursOriginal, minutesOriginal] = originalPointInput.value.split(':').map(Number);
const [hoursLeft, minutesLeft] = timeLeftInput.value.split(':').map(Number);
const [hoursSection, minutesSection] = sectionDurationInput.value.split(':').map(Number);
let totalHours = hoursOriginal - hoursLeft;
let totalMinutes = minutesOriginal - minutesLeft;
if (totalMinutes < 0) {
totalHours--;
totalMinutes += 60;
}
let endHours = totalHours;
let endMinutes = totalMinutes + minutesSection;
if (endMinutes >= 60) {
endHours += Math.floor(endMinutes / 60);
endMinutes = endMinutes % 60;
}
const startTimeFormatted = `${totalHours.toString().padStart(2, '0')}:${totalMinutes.toString().padStart(2, '0')}`;
const endTimeFormatted = `${endHours.toString().padStart(2, '0')}:${endMinutes.toString().padStart(2, '0')}`;
output.value = `${startTimeFormatted} - ${endTimeFormatted}`;
} else {
alert('Please fill in all the fields.');
}
}
</script>
</head>
<body>
<h1>How Long is it?<br>
<input id="original-point-input" name="Time" type="text"></h1>
<h1>How Much time left from the current position?<br>
<input id="time-left-input" name="Time" type="text"></h1>
<h1>Optional (How long is the section in question?)<br>
<input id="section-duration-input" name="SectionInQuestion" type="text"></h1>
<h1>The original point is<br>
<input id="output" readonly type="text"></h1>
<button onclick="calculateOriginalPoint()">Calculate</button>
</body>
</html>
In this optimized code, the typo in the style type attribute has been fixed. Also, the usage of smart quotes (‘’) has been replaced with regular quotes ('') to ensure the code works properly. Additionally, unnecessary string interpolation has been removed. The input element attributes have been cleaned up, removing unnecessary quotes and self-closing tags.