Page MenuHomePhabricator

Lua Task 6 - Tests
Closed, DeclinedPublic

Description

Prerequisite: Lua Task 5 - Calculations. This task requires independent learning and is more difficult.

Note that a Scribunto function always returns a string (i.e. text) to the Wikipedia page where it is invoked. Lua variables are dynamically-typed. That means that variables do not have a type, only values have a type. Lua will generally do its best to convert from one type to another as needed. For example, you can concatenate text with numbers without having to explicitly convert the number to a string first.

Lua uses the if <test> then <do-if-true> else <do-if-false> end structure to pick one of two outcomes depending on whether the test turns out true or false.

1 In your module sandbox, amend the function "temperature" to supply 0 as the default if no parameter is supplied. Save it.

2 Write a line in your sandbox to test that. Save it.

3 Make changes to the function "temperature" to store the text that you are returning in a variable called "msg". Then return msg as the last line before the end of the function. Save it and check in your sandbox that it is still working.

4 Change function "temperature" to test whether the value of "cel" is greater than (>) 9. If it is, then add " It is warm." to "msg", otherwise add " It is cold." - you'll need the concatenation operator (..) and a construction like msg = msg .. " blah blah".

5 Test your function in your sandbox with different values of the parameter to make sure that the test works as expected.

Event Timeline

RexxS created this task.Dec 13 2017, 3:02 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptDec 13 2017, 3:02 PM
RexxS added a comment.Dec 13 2017, 3:02 PM

I will mentor this in Google-Code-in 2017.

RexxS updated the task description. (Show Details)Dec 13 2017, 5:45 PM
Aklapper closed this task as Declined.Jan 17 2018, 6:28 PM

Closing this task as it was a placeholder in Phab for Google-Code-in-2017 which is ending these days (no more new tasks can be claimed from now on in GCI 2017).