user device detection with javascript [closed]

my html:

<li data-memberId="{$row['member_id']}"></li>

I want to show user device Icon behind of usernames. for this I write below javascript code but I don’t know how to implement that.

my javascript:

if (window.matchMedia("(max-width: 768px)").matches)
{
  document.write("fa-mobile");  
}  
else  
{  
  document.write("fa-desktop");  
}

just I want to display user device (mobile or desktop or tablet)