Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to turn a time into a word js


const time = (h, m) => {
    let count = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "twenty one", "twen two", "twenty three", "twenty four", "twenty five", "twenty six", "twenty seven", "twenty eight", "twenty nine", "thirty"]
    if (m === 1) {
      return count[m] + " minute past " + count[h];
    } else
    if (m === 59) {
      return count[60 - m] + " minute to " + count[h + 1];
    } else
    if (m === 0 ) {
      return count[h] + " o'clock"; 
    } else
    if (m === 15) {
      return "Quarter past " + count[h];
    } else
    if (m === 30) {
      return "half past " + count[h];
    } else 
    if (m === 45) {
      return "Quarter to " + count[h];
    } else
    if (m < 30) {
      return count[m] + " minutes past " + count[h];
    } else 
    if (m > 30) {
      return count[60 - m] + " minutes to " + count[h + 1];
    }
  };
  console.log(time(5, 0));
  console.log(time(5, 1));
  console.log(time(5, 2));
  console.log(time(5, 15));
  console.log(time(5, 27));
  console.log(time(5, 30));
  console.log(time(5, 35));
  console.log(time(5, 45));
  console.log(time(5, 47));
  console.log(time(5, 59));
Comment

PREVIOUS NEXT
Code Example
Javascript :: _.extend can be used to attach functions to a prototype like this 
Javascript :: converting JSON to jsObject 
Javascript :: Will Yield A "Function" 
Javascript :: React Native Component with Random Hexa 
Javascript :: Javascript Recursion shuffle card 
Javascript :: Update array with new object JavaScript without using index 
Javascript :: https://graph.instagram.com/14.0/17841450694979740 
Javascript :: keep nav open when child item is active 
Javascript :: Add Methods to a Constructor Function Using Prototype 
Javascript :: Html() is a JQuery Function 
Javascript :: asp.net updatepanel autoscroll fix 
Javascript :: ipinfo location javascript 
Javascript :: telerik mvc grid add row 
Javascript :: what happens if pass argument to a function that does not have parameters javascript 
Javascript :: get html from url in react js 
Javascript :: regex mobile 
Javascript :: react js public folder image path search 
Javascript :: javascript change favicon dynamicly 
Javascript :: external routes in nodejs api 
Javascript :: $Javascript $.get( 
Javascript :: jquery datatable searchpane pagination not working 
Javascript :: javascript coding problems 
Javascript :: jquery show only first elements of table 
Javascript :: node-js-eacces-error-when-listening-on-most-ports 
Javascript :: Change tilte alert 
Javascript :: copy array using spread operator 
Javascript :: Expo Location Error: Unhandled promise rejection: Error: Not authorized to use background location services 
Javascript :: how to create your own event emitter in javascript 
Javascript :: Delete Button not working with json server using angularjs 
Javascript :: set default value in dynamic dropdown angularjs 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =