wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> data;
int data; cin >> data;
Declare variable.
C++
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
["result", 21]
["result", 21]
Correct.
JSON
if (b = 71)
if (b == 71)
Use ==.
Scala
if val = 34 {{}}
if val == 34 {{}}
Use ==.
Swift
53z = 10
z53 = 10
Variable cannot start with digit.
Python
for c in range(51) print(c)
for c in range(51): print(c)
Colon after for.
Python
print 'output'
print 'output';
Add semicolon.
Perl
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
if index = 89
if index == 89
Use ==.
MATLAB
let str = String::from("data"); let r=&str; str.push_str("!");
let mut str = String::from("data"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
let vec=vec![30,28,76]; let primary=&vec[0]; vec.push(80);
let mut vec=vec![30,28,76]; let primary=vec[0]; vec.push(80);
Copy instead of reference.
Rust
function foo(z) print(z) end
function foo(z) print(z) end
Correct.
Lua
let num = 51;
let num = 51;
Correct.
JavaScript
const a;
const a = 29;
Initialize const.
JavaScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{'age':26, 'status' 97}}
{{'age':26, 'status':97}}
Colon missing.
Python
for (int i=0; i<34; i++) {{}}
for (int i=0; i<34; i++) {{}}
Correct.
Java
arr[89]
if arr.indices.contains(89) {{ arr[89] }}
Check index.
Swift
List(100,34,73)
List(100,34,73)
Correct.
Scala
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
items[45]
if (length(items) >= 45) items[45]
Check length.
R
println('hello')
println("hello")
Double quotes.
Scala
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
INSERT INTO items VALUES ('message',88)
INSERT INTO items (age, role) VALUES ('message',88);
Specify columns.
SQL
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
let a = 80; let a = 27;
let a = 80; a = 27;
Duplicate declaration.
JavaScript
while val > 36 val -= 1
while val > 36: val -= 1
Colon missing after while.
Python
$x = 12; if ($x = 12) {{}}
$x = 12; if ($x == 12) {{}}
Use ==.
PHP
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
UPDATE items SET name='result' WHERE email=25
UPDATE items SET name='result' WHERE email=25;
Add semicolon.
SQL
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
DELETE FROM users WHERE id=32
DELETE FROM users WHERE id=32;
Add semicolon.
SQL
print 'value'
print('value')
print needs parentheses.
Python
var x = 44;
var x = 44;
Correct.
Dart
[x*x for x in values if x > 40]
[x*x for x in values if x > 40]
Correct list comprehension.
Python
let bar: number | null = null; bar.toFixed(69);
let bar: number | null = null; if(bar!==null) bar.toFixed(69);
Null check.
TypeScript
if ($num = 86)
if ($num == 86)
Use ==.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[36, 63, 30
[36, 63, 30]
Close bracket.
Ruby
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
my @arr = (48,50,98);
my @arr = (48,50,98);
Correct.
Perl
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
class Item {{ int a; }} obj.a=5;
class Item {{ public int a; }} obj.a=5;
Make field public.
Java
let item = 'output'
let item = "output"
Double quotes.
Swift
SELECT * FROM items WHRE id=20;
SELECT * FROM items WHERE id=20;
Fix WHERE.
SQL
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:70}};
Add missing property.
TypeScript
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
switch(count){{ case 32: break; }}
switch(count){{ case 32: break; default: break; }}
Add default case.
Java
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(4);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(4);
Correct.
Node.js
def bar puts 'hello' end
def bar puts 'hello' end
Correct.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Order def method end end
class Order def method end end
Correct.
Ruby
int index = 'data';
String index = 'data';
Type mismatch.
Dart
if ($val = 44) {{}}
if ($val -eq 44) {{}}
Use -eq.
PowerShell
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
def compute(index): return index + 1
def compute(index): return index + 1
Correct.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
WHERE name = '10'
WHERE name = 10
Don't quote integer.
SQL
arr(84)
if length(arr) >= 84, arr(84), end
Check length.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$list[12]
if ($list.Count -gt 12) {{ $list[12] }}
Check bounds.
PowerShell
let val: number = 'test';
let val: string = 'test';
Fix type.
TypeScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
<note><name>output</name><age>9</age></note
<note><name>output</name><age>9</age></note>
Add closing >.
XML
object Item {{ def main(args: Array[String]) = println("output") }}
object Item {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
h1 {{ font-size:67px color:#333; }}
h1 {{ font-size:67px; color:#333; }}
Add semicolon.
CSS
if (b = 56)
if (b == 56)
Use ==.
C++
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
values[62]
if (values.indices.contains(62)) values[62]
Check index.
Kotlin
int[] arr = new int[57]; arr[57] = 5;
int[] arr = new int[57]; if (57 < arr.length) arr[57] = 5;
Check bounds.
Java
assert foo > 6
assert foo > 6
Correct.
Python
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
id: world name: test,
id: world name: test
Remove comma.
YAML
num == '3'
num === 3
Use strict equality.
JavaScript
'hello' + 19
'hello' + str(19)
Can't add int to string.
Python
var x int
var x int
Correct.
Go
let mut result=27; let r1=&mut result; let ref2=&mut result;
let mut result=27; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const c = 25; c = 40;
let c = 25; c = 40;
Cannot reassign const.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
yield a
yield a
Correct yield.
Python
test
test()
Add parentheses.
Kotlin
val num: Int = 'world'
val num: String = 'world'
Fix type.
Kotlin
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if result = 43
if result == 43
Use ==.
Ruby
z = test
z = 'test'
Quote strings.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
b > 68 & x < 10
b > 68 and x < 10
Use 'and' not '&'.
Python
if a = 6:
if a == 6:
Use == for comparison.
Python
for i=1,29 do print(i) end
for i=1,29 do print(i) end
Correct.
Lua