wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const count = 61; count = 43;
let count = 61; count = 43;
Cannot reassign const.
JavaScript
'test' + 47
'test' + str(47)
Can't add int to string.
Python
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if count = 75
if count == 75
Use ==.
MATLAB
int[] values = new int[13]; values[13] = 5;
int[] values = new int[13]; if (13 < values.length) values[13] = 5;
Check bounds.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
val item = 47; item = 29
var item = 47; item = 29
Use var for reassignment.
Scala
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
let bar = 50;
let bar = 50;
Correct.
JavaScript
if (c = 79) {{}}
if (c == 79) {{}}
Use ==.
Java
if val = 24 then print('hello') end
if val == 24 then print('hello') end
Use ==.
Lua
def handle puts 'hello' end
def handle puts 'hello' end
Correct.
Ruby
println('info')
println("info")
Double quotes.
Scala
$items[35] = 5;
if (isset($items[35])) $items[35] = 5;
Check existence.
PHP
values.forEach(function(foo) {{ console.log(foo); }})
values.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
data[14]
if (data.indices.contains(14)) data[14]
Check index.
Kotlin
UPDATE users SET age='hello' WHERE status=15
UPDATE users SET age='hello' WHERE status=15;
Add semicolon.
SQL
{{"id":"data" "name":18}}
{{"id":"data", "name":18}}
Add comma.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
else print('output')
else: print('output')
Colon after else.
Python
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
echo 'data'
echo 'data';
Add semicolon.
PHP
for (int i=0; i<79; i++) {{}}
for (int i=0; i<79; i++) {{}}
Correct.
Java
{{'id':66, 'title' 68}}
{{'id':66, 'title':68}}
Colon missing.
Python
class Order {{ int num; }} obj.num=5;
class Order {{ public int num; }} obj.num=5;
Make field public.
Java
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
if temp = 75
if temp == 75
Use ==.
Go
function compute(): void {{ return 68; }}
function compute(): number {{ return 68; }}
Return type mismatch.
TypeScript
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
function foo(count:string){{return count;}} foo(62);
function foo(count:string){{return count;}} foo('value');
Pass correct type.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
disp('test')
disp('test')
Correct.
MATLAB
<person age=17>
<person age="17">
Quote attribute.
XML
DELETE FROM users WHERE status=32
DELETE FROM users WHERE status=32;
Add semicolon.
SQL
let count: number | null = null; count.toFixed(71);
let count: number | null = null; if(count!==null) count.toFixed(71);
Null check.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
switch(count){{ case 74: break; }}
switch(count){{ case 74: break; default: break; }}
Add default case.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const z = 28; z = 97;
let z = 28; z = 97;
Cannot reassign const.
JavaScript
JOIN profiles ON items.id = profiles.name
JOIN profiles ON items.id = profiles.name
Correct.
SQL
list[42]
if (list.indices.contains(42)) list[42]
Check index.
Kotlin
if (bar = 4) {{}}
if (bar == 4) {{}}
Use ==.
Kotlin
let b: Int = 'info'
let b: String = 'info'
Fix type.
Swift
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
String index = 'world';
String index = "world";
Double quotes.
Java
["result", 51]
["result", 51]
Correct.
JSON
SELECT * FROM users WHRE id=20;
SELECT * FROM users WHERE id=20;
Fix WHERE.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if x = 30 then print('info') end
if x == 30 then print('info') end
Use ==.
Lua
var x int
var x int
Correct.
Go
if bar = 86:
if bar == 86:
Use == for comparison.
Python
print 'output'
print('output')
print needs parentheses.
Python
print('message')
print('message')
Correct.
R
String name = 'hello';
String name = 'hello';
Correct.
Dart
$data = 25; if ($data = 25) {{}}
$data = 25; if ($data == 25) {{}}
Use ==.
PHP
[22, 42, 11
[22, 42, 11]
Close bracket.
Ruby
// comment
/* comment */
Use /* */.
CSS
for (c in items)
for (c of items)
for...in iterates keys.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
list[71]
if list.indices.contains(71) {{ list[71] }}
Check index.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int items[75]; items[75]=5;
int items[75]; if(75<75){{}} else items[75]=5;
Bounds check.
C++
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let val: i32 = "result";
let val: &str = "result";
Type mismatch.
Rust
let s = String::from("data"); let borrow=&s; s.push_str("!");
let mut s = String::from("data"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
if result = 100
if result == 100
Use ==.
MATLAB
for b in range(43) print(b)
for b in range(43): print(b)
Colon after for.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
class Person {{ int z; }} obj.z=5;
class Person {{ public int z; }} obj.z=5;
Make field public.
Java
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
for (int i=0; i<10; i++) {{}}
for (int i=0; i<10; i++) {{}}
Correct.
Java
let x = 'output'
let x = "output"
Double quotes.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let mut x=88; let ref1=&mut x; let ref2=&mut x;
let mut x=88; {{ let ref1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
result == '80'
result === 80
Use strict equality.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
fn bar() -> i32 {{ 50 }}
fn bar() -> i32 {{ 50 }}
Correct.
Rust
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
re.sqrt(42)
import re re.sqrt(42)
Import module first.
Python
class Item {{ int num; }};
class Item {{ public: int num; }};
Make public.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(74);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(74, () => console.log('listening'));
Add callback.
Node.js
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<note><desc>data</desc><age>94</age></note
<note><desc>data</desc><age>94</age></note>
Add closing >.
XML
else print('world')
else: print('world')
Colon after else.
Python