Page MenuHomePhabricator

Lua Task 5 - Calculations
Closed, DeclinedPublic

Description

Prerequisite: Lua Task 4 - Passing information to your Lua module. This task requires some independent learning.

In a Lua function, we can do the usual programming jobs, such as calculations, text processing, testing and repeating blocks of code. You'll need to read The Reference Manual if you are uncertain about anything.

1 In your module sandbox, create a new function called "temperature". In the call, we will pass a parameter named "celsius" and store it inside the function as a variable named "cel". We will then convert it to fahrenheit and store it in a variable named "fah". Finally, we will return both values along with some text.

Use the line

cel = frame.args.celsius

to get the parameter "celsius" and store it in the variable "cel".

2 To convert, we multiply a value in Celsius by 9, then divide it by 5, and add 32. Write a line starting

fah =

to do that conversion. You'll need the multiplication (*), division (/), and addition (+) operators.

3 Write a line of code that returns something like "15 degrees Celsius is 59 degrees Fahrenheit." when the function is passed 15 as the |celsius= parameter. Save your module sandbox. You'll need the concatenation (..) operator.

4 In your sandbox, write a line that calls your module sandbox function "temperature", passing 5 as the parameter, Write another line that calls the function with 25 as the parameter. Save your sandbox. Fix any errors that occur.

Event Timeline

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

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).