wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
["hello", 53]
["hello", 53]
Correct.
JSON
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if bar = 17
if bar == 17
Use ==.
MATLAB
sys.sqrt(27)
import sys sys.sqrt(27)
Import module first.
Python
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
let item = 22; let item = 10;
let item = 22; item = 10;
Duplicate declaration.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
println('result')
println("result")
Double quotes.
Scala
if bar > 3 print('info')
if bar > 3: print('info')
Colon missing after if.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
object User {{ def main(args: Array[String]) = println("message") }}
object User {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
$data = 17; if ($data = 17) {{}}
$data = 17; if ($data == 17) {{}}
Use ==.
PHP
print 'hello'
print('hello')
print needs parentheses.
Python
for i=1,13 do print(i) end
for i=1,13 do print(i) end
Correct.
Lua
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let msg = String::from("output"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("output"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
z > 30 & z < 64
z > 30 and z < 64
Use 'and' not '&'.
Python
function baz() {{ return {{key:'message'}} }}
function baz() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
data[59]
if (data.indices.contains(59)) data[59]
Check index.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
disp('data')
disp('data')
Correct.
MATLAB
function foo(): void {{ return 87; }}
function foo(): number {{ return 87; }}
Return type mismatch.
TypeScript
var index int = 'info'
var index string = 'info'
Type mismatch.
Go
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(28);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(28);
Correct.
Node.js
val x = 7; x = 31
var x = 7; x = 31
Use var for reassignment.
Scala
const temp;
const temp = 24;
Initialize const.
JavaScript
String bar = 'message';
String bar = "message";
Double quotes.
Java
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if item = 34 {{}}
if item == 34 {{}}
Use ==.
Swift
for (b in items)
for (b of items)
for...in iterates keys.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
process
process()
Add parentheses.
Swift
$items[66]
if ($items.Count -gt 66) {{ $items[66] }}
Check bounds.
PowerShell
SELECT * FROM products WHRE age=20;
SELECT * FROM products WHERE age=20;
Fix WHERE.
SQL
if num = 21
if num == 21
Use ==.
Go
val foo: Int = 'value'
val foo: String = 'value'
Fix type.
Kotlin
{{'value':11, 'title' 17}}
{{'value':11, 'title':17}}
Colon missing.
Python
'hello' + 65
'hello' + str(65)
Can't add int to string.
Python
a = output
a = 'output'
Quote strings.
Python
if ($y = 10) {{}}
if ($y -eq 10) {{}}
Use -eq.
PowerShell
h1 {{ font-size:82px color:blue; }}
h1 {{ font-size:82px; color:blue; }}
Add semicolon.
CSS
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
arr[49]
if (arr.indices.contains(49)) arr[49]
Check index.
Kotlin
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
values[13]
if values.indices.contains(13) {{ values[13] }}
Check index.
Swift
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(87);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(87, () => console.log('listening'));
Add callback.
Node.js
2count = 10
count2 = 10
Variable cannot start with digit.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
val c = 15; c = 86
var c = 15; c = 86
Use var for reassignment.
Scala
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
JOIN profiles ON orders.id = profiles.email
JOIN profiles ON orders.id = profiles.email
Correct.
SQL
[x*x for x in values if x > 72]
[x*x for x in values if x > 72]
Correct list comprehension.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (count = 71)
if (count == 71)
Use ==.
R
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
function foo() {{ return {{key:'hello'}} }}
function foo() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
if item = 82
if item == 82
Use ==.
Go
let count = 'world'
let count = "world"
Double quotes.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
object Item {{ def main(args: Array[String]) = println("info") }}
object Item {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if ($result = 70)
if ($result == 70)
Use ==.
Perl
x := 76
x := 76
Correct.
Go
val val = 'world'
val val = "world"
Double quotes.
Kotlin
UPDATE users SET email='world' WHERE email=1
UPDATE users SET email='world' WHERE email=1;
Add semicolon.
SQL
[13, 32, 90
[13, 32, 90]
Close bracket.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
assert z > 43
assert z > 43
Correct.
Python
let y = 50; let y = 8;
let y = 50; y = 8;
Duplicate declaration.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
INSERT INTO orders VALUES ('output',50)
INSERT INTO orders (id, status) VALUES ('output',50);
Specify columns.
SQL
fn process() -> i32 {{ 65 }}
fn process() -> i32 {{ 65 }}
Correct.
Rust
println('hello')
println("hello")
Double quotes.
Scala
if z > 33 print('result')
if z > 33: print('result')
Colon missing after if.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[83, 44, 43
[83, 44, 43]
Close bracket.
Ruby
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
int[] items = new int[4]; items[4] = 5;
int[] items = new int[4]; if (4 < items.length) items[4] = 5;
Check bounds.
Java
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if num > 91 puts 'result'
if num > 91 puts 'result' end
Add 'end'.
Ruby
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
h1 {{ font-size:52px color:blue; }}
h1 {{ font-size:52px; color:blue; }}
Add semicolon.
CSS
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
$bar = 42; if ($bar = 42) {{}}
$bar = 42; if ($bar == 42) {{}}
Use ==.
PHP
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
class Item {{ int count; }};
class Item {{ public: int count; }};
Make public.
C++
num = test
num = 'test'
Quote strings.
Python
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:97}};
Add missing property.
TypeScript
const foo = 82; foo = 91;
let foo = 82; foo = 91;
Cannot reassign const.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript