wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (val = 84) {{}}
if (val == 84) {{}}
Use ==.
Kotlin
if val = 47
if val == 47
Use ==.
Go
if (result = 76)
if (result == 76)
Use ==.
Scala
disp('world')
disp('world')
Correct.
MATLAB
if foo = 38
if foo == 38
Use ==.
MATLAB
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
86val = 10
val86 = 10
Variable cannot start with digit.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if z = 78
if z == 78
Use ==.
Ruby
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
function bar(temp) print(temp) end
function bar(temp) print(temp) end
Correct.
Lua
let data: i32 = "test";
let data: &str = "test";
Type mismatch.
Rust
jwt.sign({{id:62}}, 'password');
jwt.sign({{id:62}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
name: info age: 5
name: info age: 5
Correct.
YAML
if foo > 47 print('hello')
if foo > 47: print('hello')
Colon missing after if.
Python
<entry><age>test</age><age>38</age></entry
<entry><age>test</age><age>38</age></entry>
Add closing >.
XML
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
if y = 30:
if y == 30:
Use == for comparison.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(82);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(82);
Correct.
Node.js
z == '13'
z === 13
Use strict equality.
JavaScript
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var temp int = 'result'
var temp string = 'result'
Type mismatch.
Go
if (foo = 50)
if (foo == 50)
Use ==.
C++
<br></br>
<br>
Self-closing.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[87, 6, 37
[87, 6, 37]
Close bracket.
Ruby
let c: Int = 'data'
let c: String = 'data'
Fix type.
Swift
const c;
const c = 50;
Initialize const.
JavaScript
int data[72]; data[72]=5;
int data[72]; if(72<72){{}} else data[72]=5;
Bounds check.
C++
List(81,85,86)
List(81,85,86)
Correct.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
println('message')
println("message")
Double quotes.
Scala
for (int i=0; i<80; i++) {{}}
for (int i=0; i<80; i++) {{}}
Correct.
Java
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Order def method end end
class Order def method end end
Correct.
Ruby
'result' + 67
'result' + 67.to_s
Convert int.
Ruby
UPDATE orders SET name='result' WHERE role=98
UPDATE orders SET name='result' WHERE role=98;
Add semicolon.
SQL
my @arr = (63,35,89);
my @arr = (63,35,89);
Correct.
Perl
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
const num = 45; num = 91;
let num = 45; num = 91;
Cannot reassign const.
JavaScript
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let c: i32 = "result";
let c: &str = "result";
Type mismatch.
Rust
def compute(result): return result + 1
def compute(result): return result + 1
Correct.
Python
if [ $foo = 20 ]; then
if [ "$foo" = 20 ]; then
Quote variable.
Shell
<br></br>
<br>
Self-closing.
HTML
let a: Int = 'output'
let a: String = 'output'
Fix type.
Swift
INSERT INTO items VALUES ('value',45)
INSERT INTO items (age, status) VALUES ('value',45);
Specify columns.
SQL
if result > 45 print('test')
if result > 45: print('test')
Colon missing after if.
Python
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
let index = 79;
let index = 79;
Correct.
JavaScript
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (z = 13) {{}}
if (z === 13) {{}}
Use === for equality.
JavaScript
<person age=3>
<person age="3">
Quote attribute.
XML
print 'result'
print('result')
print needs parentheses.
Python
let text1 = String::from("hello"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
assert c > 23
assert c > 23
Correct.
Python
class User {{ int a; }};
class User {{ public: int a; }};
Make public.
C++
arr(31)
if length(arr) >= 31, arr(31), end
Check length.
MATLAB
val count = 'value'
val count = "value"
Double quotes.
Kotlin
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
switch(index){{ case 99: break; }}
switch(index){{ case 99: break; default: break; }}
Add default case.
Java
title: result title: data,
title: result title: data
Remove comma.
YAML
if z > 94 puts 'value'
if z > 94 puts 'value' end
Add 'end'.
Ruby
let mut foo=16; let ref1=&mut foo; let r2=&mut foo;
let mut foo=16; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
if (num = 19)
if (num == 19)
Use ==.
Scala
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
$list[55]
if ($list.Count -gt 55) {{ $list[55] }}
Check bounds.
PowerShell
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
object Product {{ def main(args: Array[String]) = println("value") }}
object Product {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
println('info')
println("info")
Double quotes.
Scala
SELECT * FROM items WHRE status=68;
SELECT * FROM items WHERE status=68;
Fix WHERE.
SQL
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
var a int = 'world'
var a string = 'world'
Type mismatch.
Go
val item: Int = 'world'
val item: String = 'world'
Fix type.
Kotlin
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
[20, 66, 9
[20, 66, 9]
Close bracket.
Ruby
while index > 83 index -= 1
while index > 83: index -= 1
Colon missing after while.
Python
26x = 10
x26 = 10
Variable cannot start with digit.
Python
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
else print('message')
else: print('message')
Colon after else.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for (x in values)
for (x of values)
for...in iterates keys.
JavaScript
index == '72'
index === 72
Use strict equality.
JavaScript
WHERE name = '66'
WHERE name = 66
Don't quote integer.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (b = 87) {}
if (b == 87) {}
Use ==.
Dart
print 'world'
print 'world';
Add semicolon.
Perl
class Order {{ int a; }} obj.a=5;
class Order {{ public int a; }} obj.a=5;
Make field public.
Java
for data in range(14) print(data)
for data in range(14): print(data)
Colon after for.
Python