Skip to content

Instantly share code, notes, and snippets.

@jerrickhakim
Created August 27, 2018 15:58
Show Gist options
  • Save jerrickhakim/6405261e4b25cbce982eaea34deb9ea2 to your computer and use it in GitHub Desktop.
Save jerrickhakim/6405261e4b25cbce982eaea34deb9ea2 to your computer and use it in GitHub Desktop.
Change img src based on time example
// JERRICK'S STATUS JS
jQuery(function(){
// get current hour
var now = new Date(Date.now());
var hour = now.getHours();
var min = now.getMinutes()
var statustitle = jQuery('#jh_status').attr('title');
if (hour >= 0 & hour <=7 ) {
jQuery('#jh_status').attr('src', 'https://d33t7gcdmhxpn0.cloudfront.net/getting-out-of-bed.png'); jQuery('#status-text h2').text("Sleeping Zzzz...");
} else if (hour >= 8 & hour <= 9 ) { jQuery('#jh_status').attr('src', 'https://d33t7gcdmhxpn0.cloudfront.net/getting-out-of-bed.png'); jQuery('#status-text h2').text("Morning!!");
} else if (hour == 10) { jQuery('#jh_status').attr('src', 'https://d33t7gcdmhxpn0.cloudfront.net/have-a-great-day.png'); jQuery('#status-text h2').text("Have a great day!");
} else if (hour >= 12 & hour <= 15) { jQuery('#jh_status').attr('src', 'https://d33t7gcdmhxpn0.cloudfront.net/good-afternoon.png'); jQuery('#status-text h2').text("Good Afternoon!");
} else if (hour == 16) { jQuery('#jh_status').attr('src', 'https://d33t7gcdmhxpn0.cloudfront.net/me-hungrey.png'); jQuery('#status-text h2').text("Me Hungrey!");
} else if (hour >= 17 & hour <=18 ) { jQuery('#jh_status').attr('src', 'https://d33t7gcdmhxpn0.cloudfront.net/thinking.png'); jQuery ('#status-text h2').text("Thinking...");
} else if (hour >= 19 && hour <=24 ) { jQuery('#jh_status').attr('src', 'https://d33t7gcdmhxpn0.cloudfront.net/good-evening.png');jQuery('#status-text h2').text("Good Evening!");
} else if (hour == 11 ) { jQuery('#jh_status').attr('src', 'https://d33t7gcdmhxpn0.cloudfront.net/coffee.png'); jQuery('#status-text h2').text("Coffee?");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment