FizzBuzz with a for loop
for (let i = 1; i <= 15; i++) {
const word = (i % 3 === 0 ? "Fizz" : "") + (i % 5 === 0 ? "Buzz" : "");
console.log(word || i);
}
Write JavaScript and run it right here. It runs in your browser, so nothing you type is uploaded.
Ready
// Runs in your browser. prompt() reads one line from the input box.
const name = prompt() ?? "world";
console.log(`Hello, ${name}!`);
for (let i = 1; i <= 3; i++) {
console.log(i, "squared is", i * i);
}
Type the input before you run. Each prompt() call reads the next line.
Press Run or Ctrl+Enter to see the output here.Runs in your browser with Browser JavaScript (Web Worker). Your code is not sent to a server.
Runtime: Browser JavaScript (Web Worker)
Your code runs in your browser's own JavaScript engine, inside a Web Worker that is kept apart from the page. Modern syntax works as written: let and const, arrow functions, classes with private fields, optional chaining, and await at the top level. console.log, console.info and console.debug go to the output; console.error and console.warn are shown as errors. Timers such as setTimeout keep the program alive until they have fired.
Everything happens on your device. The code you write is never uploaded, logged or stored on a server. Each run stops after 10 seconds and keeps up to 100,000 characters of output, so an endless loop cannot freeze the page.
This is browser JavaScript, not Node.js. require, npm packages, fs, process and the other Node APIs are not available, and because the code runs in a worker there is no document or window to draw on. Every run starts in a fresh worker, so variables and timers from the previous run are gone.
Open an example in the editor above, change it and run it. Opening an example does not run it.
for (let i = 1; i <= 15; i++) {
const word = (i % 3 === 0 ? "Fizz" : "") + (i % 5 === 0 ? "Buzz" : "");
console.log(word || i);
}
const scores = [72, 95, 58, 88, 64];
const passed = scores.filter((s) => s >= 60);
const average = scores.reduce((sum, s) => sum + s, 0) / scores.length;
console.log("passed:", passed);
console.log("average:", average.toFixed(1));
console.log("sorted:", [...scores].sort((a, b) => b - a));
class Account {
#balance = 0;
constructor(owner) {
this.owner = owner;
}
deposit(amount) {
this.#balance += amount;
return this;
}
get balance() {
return this.#balance;
}
}
const account = new Account("Ada").deposit(50).deposit(25);
console.log(account.owner, account.balance);
console.log(JSON.stringify({ owner: account.owner, balance: account.balance }));
const wait = (ms, value) => new Promise((resolve) => setTimeout(() => resolve(value), ms));
console.log("start");
const results = await Promise.all([wait(300, "slow"), wait(100, "fast")]);
console.log(results);
console.log("done");
// Each prompt() call reads the next line of the input box.
const count = Number(prompt());
let total = 0;
for (let i = 0; i < count; i++) {
total += Number(prompt());
}
console.log("sum:", total);
Input
3 10 20 30
Programs here do not stop and wait for you to type while they run. Everything your program reads comes from the input box, which you fill in before pressing Run.
Call prompt() to read the next line of the input box as a string, and convert it with Number() when you need a number. Once every line has been read, prompt() returns null, so a loop like while ((line = prompt()) !== null) reads all of the input.
Your latest JavaScript code and input are saved automatically in this browser, so they are still here when you come back. Nothing is saved on a server.
Share creates a link that carries your code inside the address itself, compressed after the # sign. Whoever opens it sees your code in the editor, and it only runs when they press Run.
| Keys | Action |
|---|---|
| Ctrl+Enter | Run the code |
| Ctrl+/ | Comment or uncomment the line |
| Tab · Shift+Tab | Indent or outdent the selection |
| Ctrl+F | Find and replace in the code |
| Ctrl+Z · Ctrl+Shift+Z | Undo / redo |
| Esc → Tab | Leave the editor with the keyboard |
On a Mac, use ⌘ instead of Ctrl.
No. The code runs in the browser's JavaScript engine, not in Node.js, so require, npm packages, the file system and process are not there. Everything in the language itself works, along with the built-ins that need no page, such as timers, Math, Date, JSON, Map, Set and Intl.
No. Your program runs in a Web Worker, which has no document or window. That separation is deliberate: code you open from a shared link cannot touch the page, your saved code or anything else in the browser. Use console output to show results.
Whatever your browser supports. Current versions of Chrome, Edge, Firefox and Safari handle modern JavaScript, including classes with private fields, optional chaining, top-level await and the newer array methods.
Yes. There is no account, no sign-up and no daily limit. The only limit is that a single run stops after 10 seconds.
No. The JavaScript runtime is downloaded into your browser and your code runs there, on your device. The site only serves the page and the runtime files; it never receives the code you write or the input you give it.
In this browser's local storage, one draft per language. It stays until you clear this site's data, and it is not synced to other devices. Use a share link to move code somewhere else.
Press Share and send the copied link. The code is compressed into the part of the link after #, which browsers never send to a server. Very long programs do not fit in a link, and the page will tell you when that happens.
Yes. It runs in any current mobile browser. On a slow connection the first run takes longer because the runtime has to be downloaded once.