Used to give strong advice or a recommendation: 'the best thing (to do) is ~' or 'you should ~'. It presents the action as the clearly sensible course for achieving a goal. Because it can sound a bit direct or authoritative, it is often used by someone with more experience advising someone else.
[Verb dictionary form] / [Verb ない-form] + ことだ
上手になりたいなら、毎日練習することだ。
Jouzu ni naritai nara, mainichi renshuu suru koto da.
If you want to get good, you should practice every day.
練習する + ことだ = the sensible thing to do is practice
風邪のときは、無理をしないことだ。
Kaze no toki wa, muri wo shinai koto da.
When you have a cold, you shouldn't overdo it.
しない + ことだ = negative advice 'you'd best not ~'
成功したければ、諦めないことだ。
Seikou shitakereba, akiramenai koto da.
If you want to succeed, you must not give up.
諦めない + ことだ presents 'not giving up' as the key
• Only attaches to verbs (dictionary or ない-form), not to nouns or the past tense. • Can sound blunt/preachy; soften with a reason clause or a gentler form (〜といいですよ, 〜ほうがいいですよ) in delicate situations. • Do not confuse with 〜ことだ used as exclamation (that requires a degree word — see ことか).
The JLPT rarely asks whether you recognise a pattern — it asks which of several similar patterns fits. These are the ones ~ことだ is tested against.
ほうがいい gives softer, case-by-case advice; ことだ presents the action as the essential, obviously correct thing to do.
べきだ states a moral/social obligation ('ought to'); ことだ gives practical advice for reaching a personal goal.
Study Japanese grammar on LenGaki

Get the Android app
The app adds offline study, home-screen widgets, stroke-order tracing, speaking practice with pronunciation scoring, and an AI tutor that answers questions in context — none of which fits in a browser tab.