SHARE
TWEET

js for aka name

a guest Sep 22nd, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var dayName = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
  2. var maleName = ["Kwasi", "Kwadwo", "Kwabena", "Kwaku", "Yaw", "Kofi", "Kwame"];
  3. var femaleName = ["Akosua", "Adwoa", "Abenaa", "Akua", "Yaa", "Afua", "Ama"];
  4. var year;
  5. var MM;
  6. var DD;
  7. var gender;
  8.  
  9.  
  10.  
  11.  
  12. function validate(){
  13.     // assigning my input data to the variables
  14.     var year= document.getElementById("year").value;
  15.     var MM= document.getElementById("month").value;
  16.     var DD= document.getElementById("day").value;
  17.     var gender= document.querySelector('input[name="gender"]:checked').value;
  18.  
  19.     // invoking the function that brings the name to be trigeered
  20.     calculateDay(gender, MM, year, DD);  
  21.  
  22.     // this is for validating that the fields are entered correctly
  23.     if(year==""){
  24.       document.getElementById("crazyoutput").innerHTML = "Please give your Year of Birth";
  25.  
  26.       return false;
  27.     }
  28.     if(MM=="" || MM<0 || MM>12){
  29.       document.getElementById("crazyoutput").innerHTML = "Please Enter the Month you were born";
  30.  
  31.       return false;
  32.     }
  33.     if(DD=="" || DD<0 || DD>31){
  34.       document.getElementById("crazyoutput").innerHTML = "Please give your Day of Birth";
  35.  
  36.       return false;
  37.     }
  38.     if(gender[0].checked== false && gender[1].checked==false){
  39.       document.getElementById("crazyoutput").innerHTML = "Please give your Gender";
  40.  
  41.       return false;
  42.     }
  43.     else{
  44.       return true;
  45.     }
  46. }
  47.  
  48. // this calculates the day and using that to get the akan name
  49. function calculateDay(gender, MM, year, DD){
  50.     console.log(DD);
  51.  
  52.     var name="";
  53.     var date= new Date(year+ "/" +MM +"/" +DD);
  54.  
  55.     var dayNumber = date.getDay();
  56.     if (gender==="male"){
  57.       name=maleName[dayNumber];
  58.     }else{
  59.       name=femaleName[dayNumber];
  60.     }
  61.     document.getElementById("crazyoutput").innerHTML = name;
  62.     return name;
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top