Presence check

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Presence check

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does a presence check test?
A That something has been entered, so the input is not empty
B That the data entered is actually true and correct
2. Which condition is a presence check on Name?
A Name <> ""
B Name = ""
3. Which condition also works as a presence check on Name?
A LENGTH(Name) = 0
B LENGTH(Name) > 0
4. A form has a required field for an email address. Which check makes sure it is not left blank?
A Range check
B Presence check
5. A student types "Zxq" into a required Name field and the presence check passes. Is this correct?
A Yes, a presence check only checks the field is not empty
B No, a presence check would reject a name that looks wrong

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Name <> "" AA presence check that is true only when Name has at least one character
2LENGTH(Name) > 0 BIF LENGTH(Email) > 0 THEN
3A presence check makes sure a required field on a form is not left blank CNo string can have a length less than 0, so this test is never true. A presence check needs LENGTH(Name) > 0.
4A presence check passes when the input is not empty DThe condition is the wrong way round. It accepts an empty Name, so it does not check that something was entered. It should be Name <> "".
5IF Name = "" THEN OUTPUT "Accepted" EWHILE Name = "" DO INPUT Name ENDWHILE
6IF LENGTH(Name) < 0 THEN FA presence check that is true only when Name is not empty, so something has been entered

Definitions

Presence check

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF Name __ "" THEN OUTPUT "Thank you" ENDIF
2.
IF ______(Name) > 0 THEN OUTPUT "Thank you" ENDIF
3.
IF LENGTH(Name) _ 0 THEN OUTPUT "Thank you" ENDIF
4.
REPEAT INPUT Name _____ Name <> ""
5.
IF Name = "" THEN ______ "Name is required" ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A INPUT Name
B IF Name = "" THEN
C OUTPUT "Accepted"
D ENDIF
Question 2
A OUTPUT "Enter your name"
B INPUT Name
C WHILE Name <> "" DO
D OUTPUT "Name required"
E INPUT Name
F ENDWHILE
Question 3
A INPUT Name
B IF LENGTH(Name) < 0 THEN
C OUTPUT "Name saved"
D ELSE
E OUTPUT "Name is required"
F ENDIF
Question 4
A REPEAT
B OUTPUT "Enter a username"
C INPUT UserName
D UNTIL UserName = ""
E OUTPUT "Welcome"
Question 5
A INPUT Surname
B Valid ← TRUE
C IF Surname = "" THEN
D Valid ← TRUE
E ENDIF
F OUTPUT Valid

Answer Key

Presence check
Section A: Quick Questions
Q1
A — That something has been entered, so the input is not empty
Q2
A — Name <> ""
Q3
B — LENGTH(Name) > 0
Q4
B — Presence check
Q5
A — Yes, a presence check only checks the field is not empty
Section B: Match the Pairs
Q1
Name <> "" → A presence check that is true only when Name is not empty, so something has been entered
Q2
LENGTH(Name) > 0 → A presence check that is true only when Name has at least one character
Q3
A presence check makes sure a required field on a form is not left blank → WHILE Name = "" DO INPUT Name ENDWHILE
Q4
A presence check passes when the input is not empty → IF LENGTH(Email) > 0 THEN
Q5
IF Name = "" THEN OUTPUT "Accepted" → The condition is the wrong way round. It accepts an empty Name, so it does not check that something was entered. It should be Name <> "".
Q6
IF LENGTH(Name) < 0 THEN → No string can have a length less than 0, so this test is never true. A presence check needs LENGTH(Name) > 0.
Section C: Definitions
Q1
Presence check — A validation check that tests something has been entered, so the input is not empty. For example, Name <> "" or LENGTH(Name) > 0 makes sure a required field is not left blank.
Section D: Fill in the Blanks
Q1
IF Name <> "" THEN OUTPUT "Thank you" ENDIF
Q2
IF LENGTH(Name) > 0 THEN OUTPUT "Thank you" ENDIF
Q3
IF LENGTH(Name) > 0 THEN OUTPUT "Thank you" ENDIF
Q4
REPEAT INPUT Name UNTIL Name <> ""
Q5
IF Name = "" THEN OUTPUT "Name is required" ENDIF
Section E: Spot the Error
Q1
B — The presence check is the wrong way round. Name = "" is true when nothing was entered, so 'Accepted' would show for an empty name. It should be IF Name <> "" THEN.
Q2
C — The loop must repeat while the name is empty, so the user is asked again. Name <> "" repeats when a name has been entered. It should be WHILE Name = "" DO.
Q3
B — A length can never be less than 0, so this condition is never true and every name is rejected. A presence check needs LENGTH(Name) > 0.
Q4
D — A REPEAT loop stops when the UNTIL condition is true. UserName = "" would stop the loop only when nothing is entered. It should be UNTIL UserName <> "".
Q5
D — When the surname is empty the presence check has failed, so Valid must be set to FALSE. Setting it to TRUE means an empty field would be accepted.