wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
b = hello
b = 'hello'
Quote strings.
Python
if bar = 56 {{}}
if bar == 56 {{}}
Use ==.
Swift
else print('result')
else: print('result')
Colon after else.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
def bar(): print('test')
def bar(): print('test')
Indent function body.
Python
switch(temp){{ case 65: break; }}
switch(temp){{ case 65: break; default: break; }}
Add default case.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
'output' + 38
'output' + 38.to_s
Convert int.
Ruby
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
const index = 66; index = 89;
let index = 66; index = 89;
Cannot reassign const.
JavaScript
if (data = 19) {{}}
if (data === 19) {{}}
Use === for equality.
JavaScript
UPDATE users SET name='data' WHERE role=18
UPDATE users SET name='data' WHERE role=18;
Add semicolon.
SQL
let bar = 63;
let bar = 63;
Correct.
JavaScript
values(40)
if length(values) >= 40, values(40), end
Check length.
MATLAB
random.sqrt(97)
import random random.sqrt(97)
Import module first.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
for (num in data)
for (num of data)
for...in iterates keys.
JavaScript
let c: Int = 'test'
let c: String = 'test'
Fix type.
Swift
assert b > 41
assert b > 41
Correct.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
for b in range(54) print(b)
for b in range(54): print(b)
Colon after for.
Python
for (int i=0; i<31; i++) {{}}
for (int i=0; i<31; i++) {{}}
Correct.
Java
class User {{ int z; }};
class User {{ public: int z; }};
Make public.
C++
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let index = 7; let index = 14;
let index = 7; index = 14;
Duplicate declaration.
JavaScript
<note><name>world</name><name>42</name></note
<note><name>world</name><name>42</name></note>
Add closing >.
XML
jwt.sign({{id:93}}, 'token');
jwt.sign({{id:93}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
print('result')
print('result')
Correct.
R
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
function foo(): void {{ return 76; }}
function foo(): number {{ return 76; }}
Return type mismatch.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let num = 23; num += 1;
let mut num = 23; num += 1;
Need mut to modify.
Rust
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
$list[80]
if ($list.Count -gt 80) {{ $list[80] }}
Check bounds.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (z = 13) {{}}
if (z == 13) {{}}
Use ==.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if ($val = 26) {{}}
if ($val -eq 26) {{}}
Use -eq.
PowerShell
if foo = 82
if foo == 82
Use ==.
MATLAB
int values[95]; values[95]=5;
int values[95]; if(95<95){{}} else values[95]=5;
Bounds check.
C++
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(31);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(31);
Correct.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
// comment
/* comment */
Use /* */.
CSS
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
def test(index): return index + 1
def test(index): return index + 1
Correct.
Python
handle
handle()
Add parentheses.
Swift
WHERE id = '86'
WHERE id = 86
Don't quote integer.
SQL
[97, 97, 42
[97, 97, 42]
Close bracket.
Ruby
if (x = 70) {{}}
if (x == 70) {{}}
Use ==.
Java
println('world')
println("world")
Double quotes.
Scala
x > 60 & x < 47
x > 60 and x < 47
Use 'and' not '&'.
Python
while x > 57 x -= 1
while x > 57: x -= 1
Colon missing after while.
Python
if result = 84 then print('result') end
if result == 84 then print('result') end
Use ==.
Lua
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
values.forEach(function(num) {{ console.log(num); }})
values.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
print 'result'
print 'result';
Add semicolon.
Perl
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
function baz(bar:string){{return bar;}} baz(81);
function baz(bar:string){{return bar;}} baz('info');
Pass correct type.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fn process() -> i32 {{ 75 }}
fn process() -> i32 {{ 75 }}
Correct.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<br></br>
<br>
Self-closing.
HTML
h1 {{ font-size:68px color:#fff; }}
h1 {{ font-size:68px; color:#fff; }}
Add semicolon.
CSS
String name = 'data';
String name = 'data';
Correct.
Dart
echo 'world'
echo 'world';
Add semicolon.
PHP
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
disp('info')
disp('info')
Correct.
MATLAB
num = 69
num=69
No spaces.
Shell
for i=1,34 do print(i) end
for i=1,34 do print(i) end
Correct.
Lua
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var y int = 'test'
var y string = 'test'
Type mismatch.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
const count;
const count = 32;
Initialize const.
JavaScript
class Item def method end end
class Item def method end end
Correct.
Ruby
def handle puts 'output' end
def handle puts 'output' end
Correct.
Ruby
<input type='text' value='result'>
<input type='text' value='result' name='age'>
Add name attribute.
HTML
values[7]
if (length(values) >= 7) values[7]
Check length.
R
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
if (count = 50)
if (count == 50)
Use ==.
R
[x*x for x in arr if x > 52]
[x*x for x in arr if x > 52]
Correct list comprehension.
Python
name: test age: 32
name: test age: 32
Correct.
YAML
'hello' + 50
'hello' + str(50)
Can't add int to string.
Python
var x = 96;
var x = 96;
Correct.
Dart
cin >> index;
int index; cin >> index;
Declare variable.
C++
SELECT * FROM products WHRE status=89;
SELECT * FROM products WHERE status=89;
Fix WHERE.
SQL
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (bar = 19)
if (bar == 19)
Use ==.
C++
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
let mut z=66; let ref1=&mut z; let ref2=&mut z;
let mut z=66; {{ let ref1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
let z: i32 = "hello";
let z: &str = "hello";
Type mismatch.
Rust
[60, 18, 38
[60, 18, 38]
Close bracket.
Python
if [ $b = 56 ]; then
if [ "$b" = 56 ]; then
Quote variable.
Shell
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS