Back

Code Challenge: Name Card

Difficulty  

divider

Objective

Print a name card to the console using only Console.WriteLine() and comments. No input, no variables, no math — just careful control of what appears on the screen.

This sounds easy, and the code is easy. Getting the output to look exactly right is the part that takes attention.

Skills to Practice

  • Printing text with Console.WriteLine()
  • Printing a blank line
  • Indenting with literal spaces inside a string
  • Writing comments that explain sections of a program

Write vs. WriteLine, Again

Activity 1.4's countdown used Console.Write() to keep several pieces on one line. That same habit is the trap here, in the opposite direction: forget to switch back to Console.WriteLine() for the start of a new section, and two lines that should be separate run together with no space at all — not even one.

One Write Left Over
Console.Write(" ");
Console.Write("STUDENT NAME");
Console.WriteLine("Junior");
Output
STUDENT NAMEJunior

Every line on this card is its own Console.WriteLine() call. If a line runs into the next one, this is almost always why.


Tasks

  • Create a new program named cc-name-card.
  • Print a border line made of 30 equals signs. Type it once and reuse the same line at the bottom.
  • Print your name in all capital letters, indented three spaces.
  • Print your grade level on the next line, indented the same amount.
  • Print one club, sport, job, or hobby on the next line, indented the same amount.
  • Print the border line again to close the card.
  • Add a comment above each section of your program saying what that section prints.
Challenge (optional)
  • Print a completely blank line between the top border and your name, and another between your last line and the bottom border. Activity 1.4 shows what to pass to Console.WriteLine() to get an empty line rather than nothing at all.

Sample Output

Sample Output
==============================
STUDENT NAME
Junior
Robotics Club
==============================

Your card should use your own information. The shape should match — same borders, same indentation on all three middle lines.


Submit

Submit your program file. It should contain:

  • Five printed lines, or seven if you did the optional challenge
  • A comment above each section

Check your output character by character before you submit. If the three middle lines are not indented by the same amount, your spacing is coming from somewhere you did not intend — and finding out where is the actual lesson here.

Commence Challenge