Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another way to write the calendar (关于日历的另一种写法) #469

Open
Kev1n3zz opened this issue Feb 27, 2022 · 4 comments
Open

Another way to write the calendar (关于日历的另一种写法) #469

Kev1n3zz opened this issue Feb 27, 2022 · 4 comments
Labels
area: JavaScript effort: small This task is a small effort. enhancement Improves an existing feature. help wanted If you know something about this topic, we would love your help!

Comments

@Kev1n3zz
Copy link

Kev1n3zz commented Feb 27, 2022

按照月份1、3、5、10、12为31天,2月不闰月28天,其余时间30天。这样借助三元运算符就不用在createCalendar中传入days
那么这种写法和历程中给出的传days的写法有什么区别呢? 即使考虑闰月,对于两种写法都是加入判断语句,似乎与不闰月没有不同。

According to the 1st, 3rd, 5th, 10th and 12th of the month, there are 31 days. February is not a leap month with 28 days, and the rest of the month has 30 days. In this way, with the help of the ternary operator, there is no need to pass in days in createCalendar.
So what is the difference between this way of writing and the way of writing days given in the process? Even if leap months are taken into account, judgment statements are added to both writing methods, which seems to be no different from non-leap months.

var select = document.querySelector('select');
var list = document.querySelector('ul');
var h1 = document.querySelector('h1');

select.onchange = function() {
  var choice = select.value;

  createCalendar(choice);
}

function createCalendar(choice) {
  (choice === 'February')? days = 28
  (choice === 'January'||choice ==='March'||choice ==='May'||choice ==='July'||choice ==='August'||choice ==='October'||choice ==='December')? days=31:days=30;
  list.innerHTML = '';
  h1.textContent = choice;
  for (var i = 1; i <= days; i++) {
    var listItem = document.createElement('li');
    listItem.textContent = i;
    list.appendChild(listItem);
  }
}

createCalendar(choice);
@caugner caugner added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Oct 10, 2023
@caugner caugner changed the title 关于日历的另一种写法 Another way to write the calendar (关于日历的另一种写法) Oct 12, 2023
@caugner
Copy link

caugner commented Oct 12, 2023

The issue seems to about this example:

<script>
const select = document.querySelector('select');
const list = document.querySelector('ul');
const h1 = document.querySelector('h1');
select.onchange = function() {
const choice = select.value;
let days = 31;
if(choice === 'February') {
days = 28;
} else if(choice === 'April' || choice === 'June' || choice === 'September' || choice === 'November') {
days = 30;
}
createCalendar(days, choice);
}
function createCalendar(days, choice) {
list.innerHTML = '';
h1.textContent = choice;
for(let i = 1; i <= days; i++) {
const listItem = document.createElement('li');
listItem.textContent = i;
list.appendChild(listItem);
}
}
createCalendar(31, 'January');
</script>

@caugner
Copy link

caugner commented Oct 12, 2023

I agree that it would be a better separation of concerns to determine the number of days in the createCalendar() function and have that function only take a single parameter choice monthName.

@caugner caugner added enhancement Improves an existing feature. help wanted If you know something about this topic, we would love your help! effort: small This task is a small effort. area: JavaScript and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Oct 12, 2023
@Vidit151003
Copy link

May I work on this? I am really interested in this issue

@bsmth
Copy link
Member

bsmth commented Mar 19, 2024

May I work on this? I am really interested in this issue

@Vidit151003 I think you can go ahead and open a pull request to fix this, it doesn't look like anyone else is working on it at the moment :) Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: JavaScript effort: small This task is a small effort. enhancement Improves an existing feature. help wanted If you know something about this topic, we would love your help!
Projects
None yet
Development

No branches or pull requests

4 participants