wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while x > 56 x -= 1
while x > 56: x -= 1
Colon missing after while.
Python
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(24);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(24);
Correct.
Node.js
local index = 40
local index = 40
Correct.
Lua
println('output')
println("output")
Double quotes.
Scala
if (index = 8)
if (index == 8)
Use ==.
R
print 'hello'
print('hello')
Parentheses for function call.
Lua
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
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
arr[68]
if arr.indices.contains(68) {{ arr[68] }}
Check index.
Swift
compute
compute()
Add parentheses.
Kotlin
<person age=79>
<person age="79">
Quote attribute.
XML
items[11]
if (length(items) >= 11) items[11]
Check length.
R
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if (val = 77)
if (val == 77)
Use ==.
Scala
String name = 'value';
String name = 'value';
Correct.
Dart
$items[4]
if ($items.Count -gt 4) {{ $items[4] }}
Check bounds.
PowerShell
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
function bar(num) print(num) end
function bar(num) print(num) end
Correct.
Lua
function render() {{ return {{key:'data'}} }}
function render() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
else print('output')
else: print('output')
Colon after else.
Python
if [ $z = 16 ]; then
if [ "$z" = 16 ]; then
Quote variable.
Shell
data[62]
if (data.indices.contains(62)) data[62]
Check index.
Kotlin
UPDATE items SET name='test' WHERE role=27
UPDATE items SET name='test' WHERE role=27;
Add semicolon.
SQL
{{"id":"test" "value":23}}
{{"id":"test", "value":23}}
Add comma.
JSON
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if item = 55 {{}}
if item == 55 {{}}
Use ==.
Swift
if (result = 90)
if (result == 90)
Use ==.
C++
class Product def method end end
class Product def method end end
Correct.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
int list[66]; list[66]=5;
int list[66]; if(66<66){{}} else list[66]=5;
Bounds check.
C++
if foo = 3 then print('result') end
if foo == 3 then print('result') end
Use ==.
Lua
[47, 95, 20
[47, 95, 20]
Close bracket.
Python
'value' + 60
'value' + 60.to_s
Convert int.
Ruby
val c = 'value'
val c = "value"
Double quotes.
Kotlin
44item = 10
item44 = 10
Variable cannot start with digit.
Python
WHERE id = '100'
WHERE id = 100
Don't quote integer.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
print 'output'
print('output')
print needs parentheses.
Python
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
let result = 88; let result = 98;
let result = 88; result = 98;
Duplicate declaration.
JavaScript
foo == '33'
foo === 33
Use strict equality.
JavaScript
{{'status':'test'}}
{{"status":"test"}}
Use double quotes.
JSON
var x = 50;
var x = 50;
Correct.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for i=1,34 do print(i) end
for i=1,34 do print(i) end
Correct.
Lua
int[] items = new int[37]; items[37] = 5;
int[] items = new int[37]; if (37 < items.length) items[37] = 5;
Check bounds.
Java
print('result')
print('result')
Correct.
R
function foo(z:string){{return z;}} foo(64);
function foo(z:string){{return z;}} foo('message');
Pass correct type.
TypeScript
<user><desc>data</desc><desc>98</desc></user
<user><desc>data</desc><desc>98</desc></user>
Add closing >.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class Product {{ int bar; }} obj.bar=5;
class Product {{ public int bar; }} obj.bar=5;
Make field public.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x := 35
x := 35
Correct.
Go
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
[91, 95, 15
[91, 95, 15]
Close bracket.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
{{'status':78, 'age' 22}}
{{'status':78, 'age':22}}
Colon missing.
Python
for (c in items)
for (c of items)
for...in iterates keys.
JavaScript
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
let item = 7;
let item = 7;
Correct.
JavaScript
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:54}};
Add missing property.
TypeScript
const bar;
const bar = 17;
Initialize const.
JavaScript
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
for (int i=0; i<53; i++) {{}}
for (int i=0; i<53; i++) {{}}
Correct.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
List(65,10,5)
List(65,10,5)
Correct.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function render(): void {{ return 7; }}
function render(): number {{ return 7; }}
Return type mismatch.
TypeScript
'info' + 94
'info' + str(94)
Can't add int to string.
Python
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
def bar puts 'value' end
def bar puts 'value' end
Correct.
Ruby
h1 {{ font-size:31px color:red; }}
h1 {{ font-size:31px; color:red; }}
Add semicolon.
CSS
bar
bar()
Add parentheses.
Swift
if ($y = 80)
if ($y == 80)
Use ==.
Perl
jwt.sign({{id:66}}, 'password');
jwt.sign({{id:66}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
let bar: Int = 'test'
let bar: String = 'test'
Fix type.
Swift
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
var index int = 'value'
var index string = 'value'
Type mismatch.
Go
let c = 38; let c = 19;
let c = 38; c = 19;
Duplicate declaration.
JavaScript
if (result = 34) {{}}
if (result == 34) {{}}
Use ==.
Java
var x = 47;
var x = 47;
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(68);
Correct.
Node.js
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
object Item {{ def main(args: Array[String]) = println("output") }}
object Item {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala