1. Home
  2. /
  3. Elixir Typing Test
  4. /
  5. Counter and Theme Toggle

Counter and Theme Toggle - Elixir Typing CST Test

Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
defmodule Counter do
def run do
count = 0
is_dark = false

update_ui = fn ->
IO.puts("Counter: #{count}")
IO.puts("Theme: #{if is_dark, do: \"Dark\", else: \"Light\"}")
end

increment = fn ->
count = count + 1
update_ui.()
end

decrement = fn ->
count = count - 1
update_ui.()
end

reset = fn ->
count = 0
update_ui.()
end

toggle_theme = fn ->
is_dark = !is_dark
update_ui.()
end

# Simulate actions
update_ui.()
increment.()
increment.()
toggle_theme.()
decrement.()
reset.()
end
end


Counter.run()
Coding works best on desktop or with an external keyboard.
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.

Counter and Theme Toggle — Elixir Code

Demonstrates a simple counter with theme toggling using Elixir variables and console output.

defmodule Counter do
	def run do
		count = 0
		is_dark = false

		update_ui = fn ->
		IO.puts("Counter: #{count}")
		IO.puts("Theme: #{if is_dark, do: \"Dark\", else: \"Light\"}")
		end

		increment = fn ->
		count = count + 1
		update_ui.()
		end

		decrement = fn ->
		count = count - 1
		update_ui.()
		end

		reset = fn ->
		count = 0
		update_ui.()
		end

		toggle_theme = fn ->
		is_dark = !is_dark
		update_ui.()
		end

		# Simulate actions
		update_ui.()
		increment.()
		increment.()
		toggle_theme.()
		decrement.()
		reset.()
	end
end

Counter.run()

Elixir Language Guide

Elixir is a functional, concurrent, fault-tolerant programming language built on the Erlang VM (BEAM). It enables highly scalable, distributed, and resilient applications - ideal for real-time systems, telecom-grade reliability, and web applications via Phoenix.

Primary Use Cases

  • ▸Highly concurrent real-time systems
  • ▸Scalable web backends (Phoenix)
  • ▸Distributed and fault-tolerant applications
  • ▸Event-driven architectures
  • ▸Messaging systems
  • ▸Telecom-level resilience workloads
  • ▸IoT and device message brokers

Notable Features

  • ▸Actor-based concurrency via BEAM
  • ▸Hot code upgrades
  • ▸Fault tolerance through supervision trees
  • ▸Pattern matching
  • ▸Lightweight processes
  • ▸Macros & metaprogramming

Origin & Creator

Created by José Valim in 2011 to bring modern tooling, metaprogramming, and extensibility to the Erlang ecosystem while preserving BEAM's reliability.

Industrial Note

Elixir thrives in telecom-grade environments, real-time systems, fintech, IoT backends, distributed messaging, soft real-time applications, scalable web platforms, low-latency systems, and systems requiring uptime measured in years.

Quick Explain

  • ▸Elixir is functional and immutable, running on the battle-tested Erlang VM.
  • ▸It excels at concurrency, fault tolerance, and massive scalability.
  • ▸Used for real-time systems, distributed apps, telecom-level reliability, and Phoenix web apps.

Core Features

  • ▸Functional programming
  • ▸Immutable data
  • ▸BEAM concurrency model
  • ▸OTP behaviours
  • ▸Pattern matching
  • ▸Metaprogramming (macros)

Learning Path

  • ▸Functional programming basics
  • ▸Pattern matching & immutability
  • ▸GenServers & OTP
  • ▸Phoenix & LiveView
  • ▸Distributed Elixir

Practical Examples

  • ▸Real-time chat server
  • ▸GenServer process example
  • ▸Phoenix web app
  • ▸Distributed task workers
  • ▸Telemetry & monitoring pipeline

Comparisons

  • ▸More concurrent and fault-tolerant than Node.js
  • ▸Simpler concurrency model than Go
  • ▸Better real-time features than Python/Django
  • ▸More scalable under load than Ruby on Rails

Strengths

  • ▸Massively scalable
  • ▸Extremely fault tolerant
  • ▸Low-latency real-time features
  • ▸Easy concurrency model
  • ▸Rock-solid reliability from BEAM

Limitations

  • ▸Smaller ecosystem compared to Python/JS
  • ▸Learning curve for FP + OTP
  • ▸Not ideal for heavy numerical computing
  • ▸Limited mobile/desktop tooling
  • ▸Requires BEAM mental model

When NOT to Use

  • ▸Heavy numerical/scientific computing
  • ▸Native mobile apps
  • ▸ML/AI workloads
  • ▸Browser-side applications
  • ▸Tiny scripts (Python is easier)

Cheat Sheet

  • ▸Pattern match: {a, b} = {1, 2}
  • ▸Function: def add(a, b), do: a + b
  • ▸Pipe operator:
  • ▸Start process: spawn(fn -> ... end)
  • ▸GenServer.start_link(Module, args)

FAQ

  • ▸Is Elixir good for large-scale apps?
  • ▸Yes-BEAM handles millions of concurrent processes effortlessly.
  • ▸Is Elixir fast?
  • ▸Fast for I/O and concurrency; slower for CPU-heavy tasks.
  • ▸Is Phoenix good for web apps?
  • ▸It's one of the fastest and most scalable web frameworks.
  • ▸Is Elixir easy to learn?
  • ▸Easier than Erlang; harder than Python/JS.

30-Day Skill Plan

  • ▸Week 1: Syntax, pattern matching
  • ▸Week 2: Processes & GenServers
  • ▸Week 3: Phoenix + LiveView
  • ▸Week 4: OTP + distributed clusters

Final Summary

  • ▸Elixir brings modern development to the Erlang ecosystem.
  • ▸It provides unmatched scalability, concurrency, and fault tolerance.
  • ▸Phoenix + LiveView makes real-time web apps extremely efficient.
  • ▸Ideal for high-availability, distributed, and real-time systems.

Project Structure

  • ▸lib/ modules
  • ▸mix.exs config
  • ▸config/ environment configs
  • ▸test/ folder
  • ▸rel/ releases

Monetization

  • ▸Real-time SaaS
  • ▸Scalable backend consulting
  • ▸IoT platforms
  • ▸Fintech microservices

Productivity Tips

  • ▸Use pipe operator heavily
  • ▸Use pattern matching everywhere
  • ▸Let BEAM handle concurrency
  • ▸Break systems into small processes

Basic Concepts

  • ▸Pattern matching
  • ▸Immutability
  • ▸Processes & messaging
  • ▸Supervision trees
  • ▸Mix build tool
  • ▸OTP behaviours (GenServer, Supervisor)

Official Docs

  • ▸Elixir Official Docs
  • ▸Erlang/OTP Docs
  • ▸Phoenix Framework Docs

More Elixir Typing Exercises

Elixir Simple CalculatorElixir FizzBuzzElixir FactorialElixir FibonacciElixir List ComprehensionElixir Map FilteringElixir Anonymous Functions with CaptureElixir Reduce Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher