Only 2 pieces of code need adding in order to show the message.
<script>
// Free Delivery message
// Get the basket total value
var basketTotal = parseFloat('{{ basket.itemTotal|number_format(2) }}');
// Check if the basket total is equal to 0 or empty
if (basketTotal === 0 || isNaN(basketTotal)) {
var message = 'Free Delivery over £50';
} else if (basketTotal < 50) {
var difference = (50 - basketTotal).toFixed(2);
var message = 'Add £' + difference + ' to qualify for free delivery.';
} else {
var message = 'You get free delivery!';
}
// Display the appropriate message
document.getElementById('delivery-message').innerText = message;
</script>