日報テンプレートのJavaScript化
✅Done
要望
タイトル部の日付
本文部
今日の日付
明日の日付
最初:
first.jslet today = new Date();
function zeroPad(num){
return num < 10 ? `0${num}` : num;
}
let dateText = `${today.getFullYear()}-${zeroPad(today.getMonth() + 1)}-${zeroPad(today.getDate())}`;
let nextday = `${tomorrow.getFullYear()}-${zeroPad(tomorrow.getMonth() + 1)}-${zeroPad(tomorrow.getDate())}`;
return {
日報 `${today.getFullYear()}-${zeroPad(today.getMonth() + 1)}-${zeroPad(today.getDate())}`
[nippou.icon]
`${today.getFullYear()}-${zeroPad(today.getMonth() + 1)}-${zeroPad(today.getDate())}`
[*_ | 今日やったこと/学んだこと/感じたこと]
[*_ | 今の気持ち(5段階評価)]
[*_ | 今日やった新体験]
翌日→[日報 `${tomorrow.getFullYear()}-${zeroPad(tomorrow.getMonth() + 1)}-${zeroPad(tomorrow.getDate())}`]
}
なにかがダメらしい
つぎ
second.jslet today = new Date();
let tomorrow = new Date(today);
tomorrow.setDate(today.getDate() + 1);
function zeroPad(num) {
return num < 10 ? 0`${num}` : num;
}
let dateText = ${today.getFullYear()}-${zeroPad(today.getMonth() + 1)}-${zeroPad(today.getDate())};
let nextday = ${tomorrow.getFullYear()}-${zeroPad(tomorrow.getMonth() + 1)}-${zeroPad(tomorrow.getDate())};
const report =[
`日報 ${dateText}`,
``,
`[nippou.icon] `,
``,
`[${dateText}]`,
``,
`[*_ | 今日やったこと/学んだこと/感じたこと]`,
` `,
``,
`[*_ | 今の気持ち(5段階評価)]`,
` `,
``,
`[*_ | 今日やった新体験]`,
` `,
``,
`翌日→日報 ${nextday}`];
うごかない!
ここらで簡単に動くようなものを作ろうと考えた
bad.jsconst name = "cFQ";
return
`${name}`
return
をおいただけでは「本文」になにか書かれるわけではない
何らかの関数の変更でなければダメなわけだ
test.jsconst today = new Date();
`${today}`
`Sun Mar 03 2024 12:28:19 GMT+0900 (日本標準時)`という形が帰ってきた
こうじゃなくて yyyy-mm-dd
の形にしたい
test3.jsconst today = new Date().toLocaleDateString('sv-SE')
`${today}`
参照
>小ネタです、JavaScriptで本日の日付をYYYY-MM-DD形式で得るコードは案外面倒です。
出力がなされない
ボタンの方でどういうどうさをやっているのか知る必要がありそう
動作するテンプレートと何が違う?
簡単な動作なら動くぞ
templa.js// 日付をYYYY-MM-DDの書式で返すメソッド
function formatDate(dt) {
var y = dt.getFullYear();
var m = ('00' + (dt.getMonth()+1)).slice(-2);
var d = ('00' + dt.getDate()).slice(-2);
return (y + '-' + m + '-' + d);
};
formatDate(new Date());
下のfomatdateの処理が抜けていたからだった
とりあえずタイトルに 2024-03-03
と表示させることはできた
これを日報に組み込むにはどうしたらいいんだろう
ヒント:一からやり直せ
この辺で困っていたら

さんが現れて啓示をいただいた
ありがとうございます!!!

template.js(function() {
var date = new Date();
var today = date.getFullYear() + '-' + ('0' + (date.getMonth() + 1)).slice(-2) + '-' + ('0' + date.getDate()).slice(-2);
var tomorrow = new Date(date);
tomorrow.setDate(date.getDate() + 1);
var nextDay = tomorrow.getFullYear() + '-' + ('0' + (tomorrow.getMonth() + 1)).slice(-2) + '-' + ('0' + tomorrow.getDate()).slice(-2);
return `日報 ${today}
[nippou.icon] ${today}
明日→[日報 ${nextDay}]
`;
})()

さんから大ヒントを色々いただきました
undefined
ChatGPT先生に添削を頼んだら function(generateDate()
メソッドを使うべしと言われたので入れたが、これが悪さをしていたらしい
これで動いた!

苦闘の跡
✌️
