CodeDrill
day_streak: --
← 問題一覧に戻る
JavaScript ・ Forms

Problem 70: Validate Input Before Greeting

When a name is entered into the input field #nameInput and the button #greetBtn is pressed, display "Welcome, 〇〇" (where 〇〇 is the entered name) in the paragraph #message.

However, if the input is empty or contains only spaces, display "Please enter your name" instead. Remove any extra spaces before and after the name.

What you'll train

Cover the edge cases

What you get

  • Specify how empty input is handled
  • Specify string trimming
  • Clarify the branching condition

How to ask the AI

Clearly tell the AI the condition for displaying "Please enter your name": when the input is empty or contains only spaces. Don't forget to also specify that extra spaces before and after the name should be removed.

If you ask vaguelyThe AI may only check for an empty string, treating input that consists only of spaces (" ") as a valid name.

あなたのコード

実行しました

プレビュー

AIレビュー(プロンプト練習)

コードはChatGPTやClaudeに出させたものを貼って構いません。
ここでの本番は「次にAIへ出す指示」です。評価軸は1つだけ見て、弱点・指示の穴・改善例を返します。
テストに落ちていてもレビューできます。落ちた理由と、指示に足りなかった情報を結びつけます。

先にコードを実行し、テストを1つ以上通してください。