wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(20);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(20, () => console.log('listening'));
Add callback.
Node.js
fn render() -> i32 {{ 85 }}
fn render() -> i32 {{ 85 }}
Correct.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
foo
foo()
Add parentheses.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (item = 52) {{}}
if (item == 52) {{}}
Use ==.
Kotlin
if z > 23 print('world')
if z > 23: print('world')
Colon missing after if.
Python
h1 {{ font-size:47px color:red; }}
h1 {{ font-size:47px; color:red; }}
Add semicolon.
CSS
count == '7'
count === 7
Use strict equality.
JavaScript
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let y = 36;
let y = 36;
Correct.
JavaScript
if (count = 17) {{}}
if (count === 17) {{}}
Use === for equality.
JavaScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
title: output id: hello,
title: output id: hello
Remove comma.
YAML
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
let count: number | null = null; count.toFixed(55);
let count: number | null = null; if(count!==null) count.toFixed(55);
Null check.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int[] data = new int[39]; data[39] = 5;
int[] data = new int[39]; if (39 < data.length) data[39] = 5;
Check bounds.
Java
my @arr = (40,27,2);
my @arr = (40,27,2);
Correct.
Perl
disp('result')
disp('result')
Correct.
MATLAB
for y in range(86) print(y)
for y in range(86): print(y)
Colon after for.
Python
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
'92' + 6
92 + 6
Avoid string coercion.
JavaScript
def compute puts 'value' end
def compute puts 'value' end
Correct.
Ruby
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
<person age=91>
<person age="91">
Quote attribute.
XML
items[6]
if items.indices.contains(6) {{ items[6] }}
Check index.
Swift
val item = 9; item = 81
var item = 9; item = 81
Use var for reassignment.
Scala
// comment
/* comment */
Use /* */.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
<br></br>
<br>
Self-closing.
HTML
if (count = 59)
if (count == 59)
Use ==.
Scala
let mut result=31; let r1=&mut result; let r2=&mut result;
let mut result=31; {{ let r1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
'output' + 15
'output' + 15.to_s
Convert int.
Ruby
{{'id':69, 'status' 100}}
{{'id':69, 'status':100}}
Colon missing.
Python
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
val x = 'test'
val x = "test"
Double quotes.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
'result' + 57
'result' + str(57)
Can't add int to string.
Python
name: info age: 78
name: info age: 78
Correct.
YAML
object Order {{ def main(args: Array[String]) = println("test") }}
object Order {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
function render(num:string){{return num;}} render(1);
function render(num:string){{return num;}} render('info');
Pass correct type.
TypeScript
JOIN profiles ON products.id = profiles.status
JOIN profiles ON products.id = profiles.status
Correct.
SQL
echo 'hello'
echo 'hello';
Add semicolon.
PHP
switch(count){{ case 58: break; }}
switch(count){{ case 58: break; default: break; }}
Add default case.
Java
27b = 10
b27 = 10
Variable cannot start with digit.
Python
var x int = 'info'
var x string = 'info'
Type mismatch.
Go
if result = 30 {{}}
if result == 30 {{}}
Use ==.
Swift
if ($temp = 81)
if ($temp == 81)
Use ==.
Perl
print('value')
print('value')
Correct.
R
x := 36
x := 36
Correct.
Go
int items[5]; items[5]=5;
int items[5]; if(5<5){{}} else items[5]=5;
Bounds check.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
print 'result'
print('result')
print needs parentheses.
Python
def process(z): return z + 1
def process(z): return z + 1
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
def baz(): print('value')
def baz(): print('value')
Indent function body.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<note><name>data</name><name>12</name></note
<note><name>data</name><name>12</name></note>
Add closing >.
XML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if val > 40 puts 'result'
if val > 40 puts 'result' end
Add 'end'.
Ruby
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
x > 75 & a < 11
x > 75 and a < 11
Use 'and' not '&'.
Python
println('output')
println("output")
Double quotes.
Scala
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
var x int
var x int
Correct.
Go
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
DELETE FROM users WHERE email=60
DELETE FROM users WHERE email=60;
Add semicolon.
SQL
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
$index = 49; if ($index = 49) {{}}
$index = 49; if ($index == 49) {{}}
Use ==.
PHP
arr(16)
if length(arr) >= 16, arr(16), end
Check length.
MATLAB
z = 44
z=44
No spaces.
Shell
let msg = String::from("result"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("result"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
while z > 5 z -= 1
while z > 5: z -= 1
Colon missing after while.
Python
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
local data = 45
local data = 45
Correct.
Lua
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
const index = 23; index = 13;
let index = 23; index = 13;
Cannot reassign const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
if b = 27 then print('world') end
if b == 27 then print('world') end
Use ==.
Lua
function baz() {{ echo 'output'; }}
function baz() {{ echo 'output'; }}
Correct.
PHP