0
0
Blockchain / Solidityprogramming~10 mins

Function declaration and syntax in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a simple function named greet.

Blockchain / Solidity
function [1]() {
  return "Hello!";
}
Drag options to blanks, or click blank then click option'
Agreet
Bwelcome
CsayHello
Dhello
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than 'greet'.
Forgetting to write the function name after 'function'.
2fill in blank
medium

Complete the code to declare a function named add that takes two parameters a and b.

Blockchain / Solidity
function add([1], b) {
  return a + b;
}
Drag options to blanks, or click blank then click option'
Ax
Bnum
Ca
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than 'a'.
Mismatching parameter names with the function body.
3fill in blank
hard

Fix the error in the function declaration by completing the missing keyword.

Blockchain / Solidity
[1] add(a, b) {
  return a + b;
}
Drag options to blanks, or click blank then click option'
Afunction
Bfunc
Cdef
Dmethod
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'func' or 'def' instead of 'function'.
Omitting the function declaration keyword.
4fill in blank
hard

Fill both blanks to declare a public function named multiply that returns the product of two numbers.

Blockchain / Solidity
function [1](uint a, uint b) public returns (uint) {
  return a [2] b;
}
Drag options to blanks, or click blank then click option'
Amultiply
B+
C*
Dsubtract
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' for multiplication.
Using a wrong function name that does not match the operation.
5fill in blank
hard

Fill all three blanks to declare a private function named subtract that takes two uint parameters and returns their difference.

Blockchain / Solidity
function [1](uint [2], uint [3]) private returns (uint) {
  return a - b;
}
Drag options to blanks, or click blank then click option'
Asubtract
Ba
Cb
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names that do not match the function body.
Using a wrong function name like 'add' instead of 'subtract'.