Back to list
JavaScript を使用して、シンプルなお歳制限年齢確認システムを構築する方法
How To Build A Simple Voting Eligibility Age Checker With JavaScript
Translated: 2026/4/25 3:00:53
Japanese Translation
私は CS 学生で、現在の学習過程を記録中です。もしこの記事が役立つと感じましたか、あるいはコードの改善に関するご提案がありましたら、お知らせください!!
年齢の合格性を確認することは、プログラミングを学ぶ学生にとって最初の重要なタスクの一つです。投票システムや運転免許証アプリ、あるいは単純な年齢ゲートにかかわらず、そのロジックは同じです。
私のこのチュートリアルでは、if/else 文を使用して、JavaScript で基本的な「Voters Eligibility Age Checker(投票者資格年齢確認器)」を構築する方法をご紹介します。
要件
基本的なテキストエディタ(VS Code もしくは Notepad など)。
コードをコンソールで実行する Web ブラウザ。
ロジック:動作方法
コードを書く前に、Plain English(普通英語)のロジックを確認しましょう。
ユーザーに年齢を询问する。
(18 歳未満の場合)、まだ資格はありません。
JavaScript コード:
'''javascript
let userAge = Number(ageInput);
if (isNaN(userAge)) {
私の課題:
ユーザーがまだ 18 歳でない場合、彼らが待つべき正確な年数を教えてくれるようにこのコードを変更することはできますか?
解決策をコメント欄にご投稿ください!!
Original Content
I'm a CS student currently documenting my learning journey. If you found this helpful or have a suggestion on how to improve the code, let me know!!!
Checking for eligibility is one of the first things we learn in programming as a student. Whether it is for a voting system, a driver's license app, or a simple age gate, the logic is the same.
In this tutorial of mine, I’ll show you how to build a basic Voters Eligibility Age Checker using JavaScript with if/else statements.
Requirement
A basic text editor (like VS Code or even Notepad).
A web browser (to run the code in the Console).
The Logic: How it Works
Before we code, let's look at the Plain English Logic:
We ask the user for their age.
Else (if they are younger than 18), they are not eligible yet.
The Java Script Code:
'''javascript
let userAge = Number(ageInput);
if (isNaN(userAge)) {
My Challenge:
Can you modify this code to tell the user exactly how many years they need to wait if they aren't 18 yet?
Post your solution in the comments!!