Hacker’s Terminal
Write code to pass test cases in a simulated terminal.

-- Hackers Terminal Lock
RegisterCommand('testhacker', function()
local challenge = [[
Write a function that checks if a number is even or odd.
The function should:
- Take a single number parameter
- Return "even" for even numbers
- Return "odd" for odd numbers
- Handle negative numbers as well
Example:
isEvenOrOdd(4) should return "even"
isEvenOrOdd(3) should return "odd"
isEvenOrOdd(-2) should return "even"
isEvenOrOdd(-3) should return "odd"
]]
local testCases = {
{ input = {4}, expected = "even" },
{ input = {3}, expected = "odd" },
{ input = {-2}, expected = "even" },
{ input = {-3}, expected = "odd" }
}
-- Expected Response
--[[
return function(n)
if n % 2 == 0 then
return "even"
else
return "odd"
end
end
]]
exports['moon-ui']:OpenHackersTerminal(
'lua', -- language
challenge, -- challenge description
300, -- time limit in seconds (5 minutes)
testCases, -- test cases
function(success)
if success then
-- Handle successful hack
print('Hack successful!')
end
end,
function(message)
-- When time Is Up
print('Time Is Up')
end
)
end)
Last updated