1. Home
  2. /
  3. Moonscript
  4. /
  5. Temperature Converter

Temperature Converter - Moonscript Typing CST Test

Loading…

Temperature Converter — Moonscript Code

Converts Celsius to Fahrenheit and vice versa.

celsiusToF = (c) -> (c * 9 / 5) + 32
fToCelsius = (f) -> (f - 32) * 5 / 9

updateUI = (temp, scale) ->
	if scale == 'C'
		print "#{temp}°C = #{celsiusToF temp}°F"
	else
		print "#{temp}°F = #{fToCelsius temp}°C"

# Simulate actions
updateUI 25, 'C'
updateUI 77, 'F'

Moonscript Language Guide

MoonScript is a high-level, dynamic programming language that compiles to Lua. It provides syntactic sugar, cleaner syntax, and modern language features like classes, comprehensions, and pattern matching, while maintaining full compatibility with Lua runtime.

Primary Use Cases

  • ▸Scripting for games (Love2D, Roblox)
  • ▸Writing concise Lua programs
  • ▸Rapid prototyping in Lua environments
  • ▸Embedding in applications with Lua runtime
  • ▸Creating libraries compatible with Lua

Notable Features

  • ▸Class-based object system
  • ▸Function comprehensions and expressions
  • ▸Destructuring assignments
  • ▸Cleaner control flow syntax
  • ▸Direct interop with Lua code

Origin & Creator

Created by Leaf Corcoran in 2012 as a way to make Lua programming more ergonomic and expressive.

Industrial Note

MoonScript is used in gaming, embedded scripting, and applications where Lua is standard but developers want a more modern syntax and workflow.

More Moonscript Typing Exercises

MoonScript Counter and Theme ToggleMoonScript Random Number GeneratorMoonScript Todo ListMoonScript StopwatchMoonScript Dice RollerMoonScript Countdown TimerMoonScript Name GreetingMoonScript Prime CheckerMoonScript Shopping Cart

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher