🟨 JavaScript
Easy
🕐 3 min

Square Function: square

Goal: create a function square(num) that returns the square of the given number.

💡 Solution hint:
  • Squaring a number means multiplying it by itself
  • You can use the * operator
  • Or the Math.pow(num, 2) method
  • Or the exponentiation operator **
👀 Peek at solution:
function square(num) {
  return num * num;
}
 
window.square = square;

Why this way:

  1. The operation num * num is simple, fast, and clear.
  2. No extra dependencies, it uses built‑in JavaScript arithmetic.
  3. Works for integers, floats, and negative numbers.

Task description

Create a function square that takes a number and returns its square.

How the function should work:

  1. Takes one parameter — a number
  2. Returns the result of squaring that number
  3. Should work correctly with negative and floating‑point numbers

Usage examples:

square(3); // 9
square(-4); // 16
square(1.5); // 2.25

Requirements:

  • The function must be named square
  • Takes one argument — a number
  • Returns a number equal to the square of the argument
  • Must work for any number, including negative and floating‑point numbers
  • Must not cause side effects

🧑‍💻 It's not a bug! It's a feature!

The code editor is intentionally hidden on mobile.

Believe me, it's for the best: I am protecting you from the temptation to code in less-than-ideal conditions. A small screen and a virtual keyboard are not the best tools for a programmer.

📖 Now: Study the task, think through the solution. Act like a strategist.

💻 Later: Sit down at your computer, open the site, and implement all your ideas comfortably. Act like a code-jedi!