Guest User

Untitled

a guest
Jun 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. console.log("PICO Y PLACA Program");
  2. //Variables declaration
  3. let eTime = new Date();
  4. let licensePlate = prompt("Placa?","");
  5. const actualTime = new eDate();
  6. const pp = new ePlate();
  7. pp.eSplit();
  8. pp.eCompare();
  9. pp.eCompareHours();
  10.  
  11.  
  12. function ePlate(){
  13. let plate, plateStr, plateInt, plateLast; //split function eSplit
  14. let days, hours, aTime = ['T07:00:00Z','T09:30:00Z','T16:00:00Z','T17:30:00Z']; //schedule to funcion eCompare
  15. plate=licensePlate;
  16.  
  17. this.eSplit = function(){
  18. plateStr = plate.slice(0,3);//First 3 letter of the plate
  19. //console.log(plateStr.toLocaleUpperCase());
  20. plateInt = (plate.slice(3));
  21. //console.log(plateInt);//Last Digit of the plate
  22. plateLast = (plate.slice(-1));
  23. console.log("The last digit of your plate is: "+plateLast);
  24. };
  25.  
  26. this.eCompare = function(){
  27. if(plateLast==0 && eTime.getDay()==5){
  28. days==5;
  29. }
  30. if ((eTime.getDay()*2)==plateLast || ((eTime.getDay()*2)-1)==plateLast){
  31. days=eTime.getDay();
  32. }else{
  33. days = 6;
  34. }
  35. //console.log(days);
  36. };
  37.  
  38. this.eCompareHours = function(){
  39. let today= new Date("T"+actualTime.strTime+"Z");
  40. let t0 = new Date(aTime[0]), t1 = new Date(aTime[1]);
  41. let t2 = new Date(aTime[2]), t3 = new Date(aTime[3]);
  42.  
  43.  
  44. if(today.getTime()>=t0.getTime() && today.getTime()<=t1.getTime() ||
  45. today.getTime()>=t2.getTime() && today.getTime()<=t3.getTime()){
  46. hours=true;
  47. }else{
  48. hours=false;
  49. }
  50. //console.log(hours);
  51. if (hours==true && days>=1 && days<6){
  52. alert("YOUR VEHICLE with plate "+plate+" IS NOT ALLOWED ON ROAD");
  53. }else{alert("Your vehicle IS allowed on road");}
  54. };
  55. }
  56.  
  57. function eDate(){
  58. let h=eTime.getHours(),m=eTime.getMinutes(),s=eTime.getSeconds();
  59. let strTime='';
  60. m= eValidate(m);
  61. s= eValidate(s);
  62. strTime=h+":"+m+":"+s;
  63. console.log(eTime.getMonth()+"/"+eTime.getDate()+"/"+eTime.getFullYear());
  64. console.log(strTime);
  65.  
  66. function eValidate(t){
  67. if(t<10){t="0"+t;};
  68. return t;
  69. };
  70. Object.defineProperty(this,'strTime',{
  71. get: function(){return strTime;}
  72. });
  73. };
Add Comment
Please, Sign In to add comment