Created
November 1, 2019 07:20
-
-
Save itochan/055a2f023eea6c4c86e7cd423a555a9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table { | |
border-collapse: collapse; | |
} | |
th, td { | |
width: 30px; | |
border: 1px solid black; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>第4回課題</title> | |
<script src="assignment.js"></script> | |
<link href="assignment.css" rel="stylesheet"> | |
</head> | |
<body> | |
<h1>2019年11月のカレンダー</h1> | |
<p> | |
<input type="button" value="カレンダーを表示する" onclick="showCalendar();"> | |
</p> | |
<table> | |
<tbody id="calendar"></tbody> | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showCalendar() { | |
const calendar = document.getElementById("calendar"); | |
calendar.innerHTML = "<tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>"; | |
let tableHtml = ""; | |
let day = 1; | |
const dayOffset = 5; | |
for (let i = 0; i < 49; i++) { | |
if (i % 7 == 0) { | |
tableHtml += "<tr>"; | |
} | |
if (i < dayOffset) { | |
tableHtml += `<td></td>`; | |
} else { | |
tableHtml += `<td>${day}</td>`; | |
day++; | |
} | |
if (i % 7 == 6) { | |
tableHtml += "</tr>"; | |
} | |
if (day > 30) { | |
break; | |
} | |
} | |
calendar.innerHTML += tableHtml; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment