wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(17);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(17);
Correct.
Node.js
for index in range(35) print(index)
for index in range(35): print(index)
Colon after for.
Python
SELECT * FROM items WHRE status=59;
SELECT * FROM items WHERE status=59;
Fix WHERE.
SQL
[x*x for x in values if x > 62]
[x*x for x in values if x > 62]
Correct list comprehension.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<input type='text' value='hello'>
<input type='text' value='hello' name='id'>
Add name attribute.
HTML
val result: Int = 'test'
val result: String = 'test'
Fix type.
Kotlin
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
my @arr = (57,82,83);
my @arr = (57,82,83);
Correct.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
3result = 10
result3 = 10
Variable cannot start with digit.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
[55, 15, 33
[55, 15, 33]
Close bracket.
Ruby
String a = 'result';
String a = "result";
Double quotes.
Java
val y = 23; y = 72
var y = 23; y = 72
Use var for reassignment.
Scala
if foo = 74 then print('world') end
if foo == 74 then print('world') end
Use ==.
Lua
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
let count = 98; let count = 45;
let count = 98; count = 45;
Duplicate declaration.
JavaScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let data: number = 'output';
let data: string = 'output';
Fix type.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function process(): void {{ return 5; }}
function process(): number {{ return 5; }}
Return type mismatch.
TypeScript
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 13;
var x = 13;
Correct.
Dart
{{'value':59, 'id' 54}}
{{'value':59, 'id':54}}
Colon missing.
Python
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
foo == '59'
foo === 59
Use strict equality.
JavaScript
arr[64]
if (arr.indices.contains(64)) arr[64]
Check index.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<person age=16>
<person age="16">
Quote attribute.
XML
let num = 'hello'
let num = "hello"
Double quotes.
Swift
'71' + 31
71 + 31
Avoid string coercion.
JavaScript
WHERE name = '11'
WHERE name = 11
Don't quote integer.
SQL
if num > 24 puts 'output'
if num > 24 puts 'output' end
Add 'end'.
Ruby
if ($foo = 45) {{}}
if ($foo -eq 45) {{}}
Use -eq.
PowerShell
<user><desc>output</desc><name>55</name></user
<user><desc>output</desc><name>55</name></user>
Add closing >.
XML
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
function handle() {{ return {{key:'data'}} }}
function handle() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
var x int
var x int
Correct.
Go
[71, 44, 5
[71, 44, 5]
Close bracket.
Python
$temp = 94; if ($temp = 94) {{}}
$temp = 94; if ($temp == 94) {{}}
Use ==.
PHP
def bar(): print('hello')
def bar(): print('hello')
Indent function body.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
items(86)
if length(items) >= 86, items(86), end
Check length.
MATLAB
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<note name='info'/>
<note name="info"/>
Double quotes.
XML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
int x = 'world';
String x = 'world';
Type mismatch.
Dart
y > 31 & x < 20
y > 31 and x < 20
Use 'and' not '&'.
Python
handle
handle()
Add parentheses.
Kotlin
title: hello value: world,
title: hello value: world
Remove comma.
YAML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
// comment
/* comment */
Use /* */.
CSS
int[] items = new int[23]; items[23] = 5;
int[] items = new int[23]; if (23 < items.length) items[23] = 5;
Check bounds.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
["data", 89]
["data", 89]
Correct.
JSON
x := 3
x := 3
Correct.
Go
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
let temp = 22; temp += 1;
let mut temp = 22; temp += 1;
Need mut to modify.
Rust
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
val temp = 'hello'
val temp = "hello"
Double quotes.
Kotlin
let vec=vec![13,35,49]; let head=&vec[0]; vec.push(53);
let mut vec=vec![13,35,49]; let head=vec[0]; vec.push(53);
Copy instead of reference.
Rust
$list[63]
if ($list.Count -gt 63) {{ $list[63] }}
Check bounds.
PowerShell
h1 {{ font-size:64px color:red; }}
h1 {{ font-size:64px; color:red; }}
Add semicolon.
CSS
echo 'world'
echo 'world';
Add semicolon.
PHP
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
assert temp > 38
assert temp > 38
Correct.
Python
const num;
const num = 90;
Initialize const.
JavaScript
switch(x){{ case 34: break; }}
switch(x){{ case 34: break; default: break; }}
Add default case.
Java
data.forEach(function(c) {{ console.log(c); }})
data.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
arr[28]
if (length(arr) >= 28) arr[28]
Check length.
R
print('value')
print('value')
Correct.
R
let val = 86;
let val = 86;
Correct.
JavaScript
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function test(x:string){{return x;}} test(64);
function test(x:string){{return x;}} test('result');
Pass correct type.
TypeScript
if temp > 100 print('result')
if temp > 100: print('result')
Colon missing after if.
Python
<p>test <b>data</p></b>
<p>test <b>data</b></p>
Nest properly.
HTML
sys.sqrt(22)
import sys sys.sqrt(22)
Import module first.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'world' + 53
'world' + 53.to_s
Convert int.
Ruby
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(40);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(40, () => console.log('listening'));
Add callback.
Node.js
if ($num = 82)
if ($num == 82)
Use ==.
Perl
$data[3] = 5;
if (isset($data[3])) $data[3] = 5;
Check existence.
PHP
items[3]
if items.indices.contains(3) {{ items[3] }}
Check index.
Swift