You are trying to use a php value in javascript without ever printing it to the page:
TRY
<?php if( $detect->isMobile() ) : ?>
<!-- only place script in page if it is mobile -->
<script type="text/javascript">
$(function() {
$( "body" ).prepend( "<p>You are on a mobile device.</p>" );
});
</script>
<?php endif ?>