Page MenuHomePhabricator

Lua Task 7 - Repeating code
Closed, DeclinedPublic

Description

Prerequisite: Lua Task 6 - Tests. This task requires independent learning and is more difficult.

Lua has several control structures: if, while, repeat, for - this task will focus on the simple numerical [[ https://www.lua.org/manual/5.3/manual.html#3.3.5 | for loop]].

1 Examine https://en.wikipedia.org/wiki/Module:Sandbox/RexxS/GCI07
The line

local num = tonumber(frame.args.num) or 2

uses a built-in Lua function called '"tonumber" which explicitly tries to convert its argument to a number. If it fails, then 2 is used instead as the value for "num".
Read through the function line-by-line and work out what each line does. The <br> is a html tag that creates a line-break, i.e. the display continues on the next line.

2 Examine https://en.wikipedia.org/wiki/User:RexxS/sandboxGCI#Lua_Task_7
This contains "test cases" for the function, which test how it behaves when given different possible inputs: nothing, blank, text, positive number, negative number.

3 Copy the function "times" into your module sandbox. Save it.

4 Edit "times" in your module sandbox so that the heading reads something like "2 times table". Save it. Test it in your sandbox. (Do that for each following instruction).

5 Edit "times" so that it displays "2 times 1 equals 2", etc.

6 Edit "times" so that it displays each table up to 12 times instead of 10 times.

7 Leave a comment here linking to your sandbox.

Event Timeline

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

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

This comment was removed by Clockery.
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).

This comment was removed by Legoktm.
Restricted Application added a subscriber: Liuxinyu970226. · View Herald TranscriptJan 14 2020, 5:39 AM
Restricted Application removed a subscriber: Liuxinyu970226. · View Herald TranscriptJan 14 2020, 5:55 AM