wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (index = 69) {{}}
if (index == 69) {{}}
Use ==.
Kotlin
if (b = 71)
if (b == 71)
Use ==.
C++
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
print 'world'
print('world')
print needs parentheses.
Python
// comment
/* comment */
Use /* */.
CSS
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:89}};
Add missing property.
TypeScript
if [ $a = 67 ]; then
if [ "$a" = 67 ]; then
Quote variable.
Shell
def foo(x): return x + 1
def foo(x): return x + 1
Correct.
Python
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(96);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(96);
Correct.
Node.js
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
arr(89)
if length(arr) >= 89, arr(89), end
Check length.
MATLAB
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
for a in range(86) print(a)
for a in range(86): print(a)
Colon after for.
Python
count == '83'
count === 83
Use strict equality.
JavaScript
def handle(): print('message')
def handle(): print('message')
Indent function body.
Python
<hr></hr>
<hr>
Self-closing.
HTML
var x int
var x int
Correct.
Go
int val = 'world';
String val = 'world';
Type mismatch.
Dart
x := 87
x := 87
Correct.
Go
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
JOIN products ON items.id = products.age
JOIN products ON items.id = products.age
Correct.
SQL
let str1 = String::from("info"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let index: number = 'test';
let index: string = 'test';
Fix type.
TypeScript
y > 19 & a < 13
y > 19 and a < 13
Use 'and' not '&'.
Python
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
class Order {{ int data; }} obj.data=5;
class Order {{ public int data; }} obj.data=5;
Make field public.
Java
int items[99]; items[99]=5;
int items[99]; if(99<99){{}} else items[99]=5;
Bounds check.
C++
if c = 71
if c == 71
Use ==.
Go
let count = 'message'
let count = "message"
Double quotes.
Swift
if c > 90 puts 'world'
if c > 90 puts 'world' end
Add 'end'.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
let result: Int = 'result'
let result: String = 'result'
Fix type.
Swift
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
List(33,1,84)
List(33,1,84)
Correct.
Scala
list[45]
if (length(list) >= 45) list[45]
Check length.
R
let b: i32 = "test";
let b: &str = "test";
Type mismatch.
Rust
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (b = 73)
if (b == 73)
Use ==.
R
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let vec=vec![21,77,19]; let head=&vec[0]; vec.push(79);
let mut vec=vec![21,77,19]; let head=vec[0]; vec.push(79);
Copy instead of reference.
Rust
function baz(z) print(z) end
function baz(z) print(z) end
Correct.
Lua
'84' + 72
84 + 72
Avoid string coercion.
JavaScript
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
let s = String::from("data"); let ref=&s; s.push_str("!");
let mut s = String::from("data"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
class User {{ int b; }} obj.b=5;
class User {{ public int b; }} obj.b=5;
Make field public.
Java
if (b = 60) {{}}
if (b == 60) {{}}
Use ==.
Java
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
def bar(temp): return temp + 1
def bar(temp): return temp + 1
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
def bar(): print('value')
def bar(): print('value')
Indent function body.
Python
x := 42
x := 42
Correct.
Go
'output' + 73
'output' + str(73)
Can't add int to string.
Python
yield b
yield b
Correct yield.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
[83, 87, 68
[83, 87, 68]
Close bracket.
Python
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
if index = 23
if index == 23
Use ==.
Go
if a = 37 {{}}
if a == 37 {{}}
Use ==.
Swift
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
WHERE name = '12'
WHERE name = 12
Don't quote integer.
SQL
if index > 16 print('hello')
if index > 16: print('hello')
Colon missing after if.
Python
if a = 56 then print('info') end
if a == 56 then print('info') end
Use ==.
Lua
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
while c > 94 c -= 1
while c > 94: c -= 1
Colon missing after while.
Python
<person age=25>
<person age="25">
Quote attribute.
XML
if [ $count = 39 ]; then
if [ "$count" = 39 ]; then
Quote variable.
Shell
if (val = 30) {{}}
if (val == 30) {{}}
Use ==.
Kotlin
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
let val: number = 'value';
let val: string = 'value';
Fix type.
TypeScript
class Person {{ int bar; }};
class Person {{ public: int bar; }};
Make public.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
function bar() {{ return {{key:'data'}} }}
function bar() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
println('test')
println("test")
Double quotes.
Scala
{{'name':8, 'age' 9}}
{{'name':8, 'age':9}}
Colon missing.
Python
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
List(69,80,92)
List(69,80,92)
Correct.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
json.sqrt(47)
import json json.sqrt(47)
Import module first.
Python
let mut item=49; let ref1=&mut item; let r2=&mut item;
let mut item=49; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
if (bar = 22) {}
if (bar == 22) {}
Use ==.
Dart
if ($data = 76)
if ($data == 76)
Use ==.
Perl
local num = 25
local num = 25
Correct.
Lua
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
switch(data){{ case 57: break; }}
switch(data){{ case 57: break; default: break; }}
Add default case.
Java