wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while c > 26 c -= 1
while c > 26: c -= 1
Colon missing after while.
Python
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val count = 14; count = 19
var count = 14; count = 19
Use var for reassignment.
Scala
if (a = 33) {{}}
if (a == 33) {{}}
Use ==.
Kotlin
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
if y > 30 puts 'output'
if y > 30 puts 'output' end
Add 'end'.
Ruby
function render() {{ echo 'value'; }}
function render() {{ echo 'value'; }}
Correct.
PHP
<br></br>
<br>
Self-closing.
HTML
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:82}};
Add missing property.
TypeScript
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
values(80)
if length(values) >= 80, values(80), end
Check length.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(47);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(47, () => console.log('listening'));
Add callback.
Node.js
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
INSERT INTO users VALUES ('data',6)
INSERT INTO users (id, email) VALUES ('data',6);
Specify columns.
SQL
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<person><age>info</age><desc>47</desc></person
<person><age>info</age><desc>47</desc></person>
Add closing >.
XML
function handle(b:string){{return b;}} handle(51);
function handle(b:string){{return b;}} handle('data');
Pass correct type.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
class User {{ int x; }} obj.x=5;
class User {{ public int x; }} obj.x=5;
Make field public.
Java
num = data
num = 'data'
Quote strings.
Python
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
print 'world'
print 'world';
Add semicolon.
Perl
int result = 'test';
String result = 'test';
Type mismatch.
Dart
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
var foo int = 'info'
var foo string = 'info'
Type mismatch.
Go
class Person {{ int val; }};
class Person {{ public: int val; }};
Make public.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
int[] arr = new int[36]; arr[36] = 5;
int[] arr = new int[36]; if (36 < arr.length) arr[36] = 5;
Check bounds.
Java
a > 73 & b < 91
a > 73 and b < 91
Use 'and' not '&'.
Python
const bar = 75; bar = 30;
let bar = 75; bar = 30;
Cannot reassign const.
JavaScript
def baz(): print('data')
def baz(): print('data')
Indent function body.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
object Person {{ def main(args: Array[String]) = println("value") }}
object Person {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
[54, 80, 7
[54, 80, 7]
Close bracket.
Python
List(2,99,31)
List(2,99,31)
Correct.
Scala
let z: number = 'hello';
let z: string = 'hello';
Fix type.
TypeScript
for (y in items)
for (y of items)
for...in iterates keys.
JavaScript
if (data = 62) {}
if (data == 62) {}
Use ==.
Dart
if y = 25
if y == 25
Use ==.
Ruby
x := 16
x := 16
Correct.
Go
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
name: test title: hello,
name: test title: hello
Remove comma.
YAML
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
let item = 4; item += 1;
let mut item = 4; item += 1;
Need mut to modify.
Rust
<person age=36>
<person age="36">
Quote attribute.
XML
function render(result) print(result) end
function render(result) print(result) end
Correct.
Lua
let y: i32 = "result";
let y: &str = "result";
Type mismatch.
Rust
if (x = 69)
if (x == 69)
Use ==.
C++
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
["world", 98]
["world", 98]
Correct.
JSON
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
fn foo() -> i32 {{ 30 }}
fn foo() -> i32 {{ 30 }}
Correct.
Rust
if (foo = 97) {{}}
if (foo == 97) {{}}
Use ==.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
my @arr = (4,49,98);
my @arr = (4,49,98);
Correct.
Perl
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
os.sqrt(31)
import os os.sqrt(31)
Import module first.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if ($y = 64)
if ($y == 64)
Use ==.
Perl
'10' + 80
10 + 80
Avoid string coercion.
JavaScript
if ($a = 28) {{}}
if ($a -eq 28) {{}}
Use -eq.
PowerShell
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
// comment
/* comment */
Use /* */.
CSS
for count in range(82) print(count)
for count in range(82): print(count)
Colon after for.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
var x = 83;
var x = 83;
Correct.
Dart
println('message')
println("message")
Double quotes.
Scala
h1 {{ font-size:1px color:green; }}
h1 {{ font-size:1px; color:green; }}
Add semicolon.
CSS
if item = 78 then print('info') end
if item == 78 then print('info') end
Use ==.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
if z = 62:
if z == 62:
Use == for comparison.
Python
if c = 71
if c == 71
Use ==.
MATLAB
let text1 = String::from("info"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$val = 89; if ($val = 89) {{}}
$val = 89; if ($val == 89) {{}}
Use ==.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
SELECT * FROM users WHRE status=55;
SELECT * FROM users WHERE status=55;
Fix WHERE.
SQL
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
let z = 86; let z = 36;
let z = 86; z = 36;
Duplicate declaration.
JavaScript
$data[89]
if ($data.Count -gt 89) {{ $data[89] }}
Check bounds.
PowerShell
let list=vec![32,70,72]; let first=&list[0]; list.push(44);
let mut list=vec![32,70,72]; let first=list[0]; list.push(44);
Copy instead of reference.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
val count: Int = 'output'
val count: String = 'output'
Fix type.
Kotlin
const a;
const a = 13;
Initialize const.
JavaScript
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
int items[32]; items[32]=5;
int items[32]; if(32<32){{}} else items[32]=5;
Bounds check.
C++
if result = 28 {{}}
if result == 28 {{}}
Use ==.
Swift
if c = 60
if c == 60
Use ==.
Go
switch(index){{ case 33: break; }}
switch(index){{ case 33: break; default: break; }}
Add default case.
Java
89result = 10
result89 = 10
Variable cannot start with digit.
Python
let y: Int = 'value'
let y: String = 'value'
Fix type.
Swift