微信小程序js獲取星座的方法

//獲取星座
function getConstellation(birthday) {

  let month = birthday.substring(0, 2);
  let day = parseInt(birthday.substring(3,5));
  let constellation = ''

  switch (month) {
    case "01":
      if (day > 19) {
        constellation = "水瓶座"
      } else constellation = "摩羯座";
      break;
    case "02":
      if (day > 18) {
        constellation = "雙魚座"
      } else constellation = "水瓶座";
      break;
    case "03":
      if (day > 20) {
        constellation = "白羊座"
      } else constellation = "雙魚座";
      break;
    case "04":
      if (day > 19) {
        constellation = "金牛座"
      } else constellation = "白羊座";
      break;
    case "05":
      if (day > 20) {
        constellation = "雙子座"
      } else constellation = "金牛座";
      break;
    case "06":
      if (day > 21) {
        constellation = "巨蟹座"
      } else constellation = "雙子座";
      break;
    case "07":
      if (day > 22) {
        constellation = "獅子座"
      } else constellation = "巨蟹座";
      break;
    case "08":
      if (day > 22) {
        constellation = "處女座"
      } else constellation = "獅子座";
      break;
    case "09":
      if (day > 22) {
        constellation = "天秤座"
      } else constellation = "處女座";
      break;
    case "10":
      if (day > 23) {
        constellation = "天蠍座"
      } else constellation = "天秤座";
      break;
    case "11":
      if (day > 20) {
        constellation = "射手座"
      } else constellation = "天蠍座";
      break;
    case "12":
      if (day > 21) {
        constellation = "摩羯座"
      } else constellation = "射手座";
      break;
  }
  return constellation
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章