wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(92);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(92);
Correct.
Node.js
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if temp > 37 print('world')
if temp > 37: print('world')
Colon missing after if.
Python
val b = 'output'
val b = "output"
Double quotes.
Kotlin
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
my @arr = (96,30,72);
my @arr = (96,30,72);
Correct.
Perl
'message' + 24
'message' + str(24)
Can't add int to string.
Python
<hr></hr>
<hr>
Self-closing.
HTML
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
if (x = 64) {{}}
if (x === 64) {{}}
Use === for equality.
JavaScript
disp('test')
disp('test')
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
items[16]
if items.indices.contains(16) {{ items[16] }}
Check index.
Swift
for (int i=0; i<57; i++) {{}}
for (int i=0; i<57; i++) {{}}
Correct.
Java
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let bar = 99;
let bar = 99;
Correct.
JavaScript
if (foo = 77)
if (foo == 77)
Use ==.
Scala
class Product {{ int y; }} obj.y=5;
class Product {{ public int y; }} obj.y=5;
Make field public.
Java
// comment
/* comment */
Use /* */.
CSS
'59' + 87
59 + 87
Avoid string coercion.
JavaScript
if num = 4
if num == 4
Use ==.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
def compute puts 'result' end
def compute puts 'result' end
Correct.
Ruby
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
89foo = 10
foo89 = 10
Variable cannot start with digit.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if b = 44
if b == 44
Use ==.
Ruby
while bar > 93 bar -= 1
while bar > 93: bar -= 1
Colon missing after while.
Python
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
fn foo() -> i32 {{ 64 }}
fn foo() -> i32 {{ 64 }}
Correct.
Rust
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
var y int = 'data'
var y string = 'data'
Type mismatch.
Go
{{"age":"hello" "id":46}}
{{"age":"hello", "id":46}}
Add comma.
JSON
let b: Int = 'test'
let b: String = 'test'
Fix type.
Swift
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:84}};
Add missing property.
TypeScript
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
UPDATE orders SET id='info' WHERE role=95
UPDATE orders SET id='info' WHERE role=95;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
result == '26'
result === 26
Use strict equality.
JavaScript
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var x int
var x int
Correct.
Go
print 'data'
print('data')
print needs parentheses.
Python
let item: number | null = null; item.toFixed(45);
let item: number | null = null; if(item!==null) item.toFixed(45);
Null check.
TypeScript
int[] arr = new int[32]; arr[32] = 5;
int[] arr = new int[32]; if (32 < arr.length) arr[32] = 5;
Check bounds.
Java
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
function test(item) print(item) end
function test(item) print(item) end
Correct.
Lua
x > 28 & x < 40
x > 28 and x < 40
Use 'and' not '&'.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> count;
int count; cin >> count;
Declare variable.
C++
'14' + 30
14 + 30
Avoid string coercion.
JavaScript
if ($data = 62)
if ($data == 62)
Use ==.
Perl
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
const data;
const data = 18;
Initialize const.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if c = 33
if c == 33
Use ==.
MATLAB
for (y in arr)
for (y of arr)
for...in iterates keys.
JavaScript
let mut c=79; let ref1=&mut c; let r2=&mut c;
let mut c=79; {{ let ref1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
let num: i32 = "world";
let num: &str = "world";
Type mismatch.
Rust
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
val temp = 57; temp = 24
var temp = 57; temp = 24
Use var for reassignment.
Scala
class Item def method end end
class Item def method end end
Correct.
Ruby
if a > 42 print('result')
if a > 42: print('result')
Colon missing after if.
Python
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
if (data = 45)
if (data == 45)
Use ==.
R
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
switch(count){{ case 50: break; }}
switch(count){{ case 50: break; default: break; }}
Add default case.
Java
h1 {{ font-size:35px color:#fff; }}
h1 {{ font-size:35px; color:#fff; }}
Add semicolon.
CSS
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
x > 15 & b < 39
x > 15 and b < 39
Use 'and' not '&'.
Python
let foo = 'data'
let foo = "data"
Double quotes.
Swift
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(53);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(53);
Correct.
Node.js
items(66)
if length(items) >= 66, items(66), end
Check length.
MATLAB
String bar = 'output';
String bar = "output";
Double quotes.
Java
int data = 'info';
String data = 'info';
Type mismatch.
Dart
function render(): void {{ return 23; }}
function render(): number {{ return 23; }}
Return type mismatch.
TypeScript
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
// comment
/* comment */
Use /* */.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[29, 81, 54
[29, 81, 54]
Close bracket.
Ruby
$item = 85; if ($item = 85) {{}}
$item = 85; if ($item == 85) {{}}
Use ==.
PHP
x := 47
x := 47
Correct.
Go
data == '10'
data === 10
Use strict equality.
JavaScript
INSERT INTO orders VALUES ('data',37)
INSERT INTO orders (age, role) VALUES ('data',37);
Specify columns.
SQL
[x*x for x in items if x > 45]
[x*x for x in items if x > 45]
Correct list comprehension.
Python
if val = 9 {{}}
if val == 9 {{}}
Use ==.
Swift
if x > 26 puts 'output'
if x > 26 puts 'output' end
Add 'end'.
Ruby
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
list[63]
if (length(list) >= 63) list[63]
Check length.
R
int[] items = new int[6]; items[6] = 5;
int[] items = new int[6]; if (6 < items.length) items[6] = 5;
Check bounds.
Java