Course outline
Course / The terminal and the language

Pass or fail

Lab

How to fetch and submit this lab

Once: install the tool and connect your account.

curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon login

Each lab: download it, edit the file named in the instructions, then submit.

gonomicon fetch week-1/10-01-pass-or-fail
cd 10-01-pass-or-fail
gonomicon submit

Go installed? gonomicon test runs the visible test on your computer first. Submitting also runs hidden checks on our server.

Goal

Fill in Result so it returns "pass" when Score is at least 50 and "fail" otherwise.

Example

Score = 72
fmt.Println(Result()) // pass

Score = 49
fmt.Println(Result()) // fail

72 is not below 50, so it passes. 49 is one short, so it fails.

Rules

  • Edit result.go. The function has a // TODO comment and a return line you will change.
  • Score is a variable outside the function. The tests give it different values, so read Score each time the function runs.
  • Use an if with a comparison on Score. Exactly 50 counts as a pass.
  • Return exactly "pass" or "fail", in lower case, with nothing else in the text.
  • Do not change the line var Score int or the line func Result() string {. Do not add imports.

What you'll practice

Asking a yes-or-no question with a comparison operator, and choosing a result with if and else.

Run it

gonomicon fetch week-1/10-01-pass-or-fail
cd 10-01-pass-or-fail
gonomicon test
gonomicon submit

Hints

  1. You need a yes-or-no question about Score. Is it at least 50? The comparison operators are >=, >, <=, <, == and !=.
  2. Use an if with Score >= 50 and return "pass" inside it. After the if, return "fail". An else works too.
  3. if Score >= 50 { return "pass" } then on the next line return "fail".

Something wrong with this lesson? Report a problem