wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function test(count:string){{return count;}} test(74);
function test(count:string){{return count;}} test('info');
Pass correct type.
TypeScript
if (foo = 67)
if (foo == 67)
Use ==.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<br></br>
<br>
Self-closing.
HTML
yield count
yield count
Correct yield.
Python
data(18)
if length(data) >= 18, data(18), end
Check length.
MATLAB
items.forEach(function(temp) {{ console.log(temp); }})
items.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
print 'world'
print('world')
print needs parentheses.
Python
disp('output')
disp('output')
Correct.
MATLAB
int val = 'message';
String val = 'message';
Type mismatch.
Dart
let str1 = String::from("message"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
function handle(): void {{ return 21; }}
function handle(): number {{ return 21; }}
Return type mismatch.
TypeScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
while b > 50 b -= 1
while b > 50: b -= 1
Colon missing after while.
Python
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(47);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(47);
Correct.
Node.js
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
'message' + 7
'message' + str(7)
Can't add int to string.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
JOIN profiles ON items.id = profiles.email
JOIN profiles ON items.id = profiles.email
Correct.
SQL
$data[48] = 5;
if (isset($data[48])) $data[48] = 5;
Check existence.
PHP
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
let count: i32 = "output";
let count: &str = "output";
Type mismatch.
Rust
if ($a = 97) {{}}
if ($a -eq 97) {{}}
Use -eq.
PowerShell
val b = 8; b = 40
var b = 8; b = 40
Use var for reassignment.
Scala
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
my @arr = (53,74,8);
my @arr = (53,74,8);
Correct.
Perl
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
let mut z=42; let r1=&mut z; let ref2=&mut z;
let mut z=42; {{ let r1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
if (val = 49) {}
if (val == 49) {}
Use ==.
Dart
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
jwt.sign({{id:43}}, 'password');
jwt.sign({{id:43}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
<person age=91>
<person age="91">
Quote attribute.
XML
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
if result = 76
if result == 76
Use ==.
Ruby
if val > 56 puts 'world'
if val > 56 puts 'world' end
Add 'end'.
Ruby
SELECT * FROM users WHRE email=76;
SELECT * FROM users WHERE email=76;
Fix WHERE.
SQL
{{"status":"value" "title":42}}
{{"status":"value", "title":42}}
Add comma.
JSON
class Product {{ int x; }} obj.x=5;
class Product {{ public int x; }} obj.x=5;
Make field public.
Java
function test(num) print(num) end
function test(num) print(num) end
Correct.
Lua
int values[60]; values[60]=5;
int values[60]; if(60<60){{}} else values[60]=5;
Bounds check.
C++
for c in range(28) print(c)
for c in range(28): print(c)
Colon after for.
Python
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
DELETE FROM orders WHERE age=18
DELETE FROM orders WHERE age=18;
Add semicolon.
SQL
let temp: number | null = null; temp.toFixed(41);
let temp: number | null = null; if(temp!==null) temp.toFixed(41);
Null check.
TypeScript
println('hello')
println("hello")
Double quotes.
Scala
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
if foo = 61
if foo == 61
Use ==.
Go
WHERE id = '77'
WHERE id = 77
Don't quote integer.
SQL
if [ $item = 89 ]; then
if [ "$item" = 89 ]; then
Quote variable.
Shell
var x int = 'output'
var x string = 'output'
Type mismatch.
Go
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function bar() {{ echo 'info'; }}
function bar() {{ echo 'info'; }}
Correct.
PHP
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
else print('test')
else: print('test')
Colon after else.
Python
name: world age: 40
name: world age: 40
Correct.
YAML
y == '98'
y === 98
Use strict equality.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{'title':90, 'status' 100}}
{{'title':90, 'status':100}}
Colon missing.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(46);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(46, () => console.log('listening'));
Add callback.
Node.js
int[] values = new int[36]; values[36] = 5;
int[] values = new int[36]; if (36 < values.length) values[36] = 5;
Check bounds.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
values[83]
if (length(values) >= 83) values[83]
Check length.
R
fn compute() -> i32 {{ 17 }}
fn compute() -> i32 {{ 17 }}
Correct.
Rust
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
["hello", 50]
["hello", 50]
Correct.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
'value' + 61
'value' + 61.to_s
Convert int.
Ruby
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
if bar = 98
if bar == 98
Use ==.
Ruby
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(24);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(24, () => console.log('listening'));
Add callback.
Node.js
const item;
const item = 6;
Initialize const.
JavaScript
list[34]
if list.indices.contains(34) {{ list[34] }}
Check index.
Swift
if (item = 32)
if (item == 32)
Use ==.
C++
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
var x int
var x int
Correct.
Go
compute
compute()
Add parentheses.
Swift
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
println('world')
println("world")
Double quotes.
Scala
$bar = 17; if ($bar = 17) {{}}
$bar = 17; if ($bar == 17) {{}}
Use ==.
PHP
for (int i=0; i<81; i++) {{}}
for (int i=0; i<81; i++) {{}}
Correct.
Java
foo = test
foo = 'test'
Quote strings.
Python
let bar: i32 = "hello";
let bar: &str = "hello";
Type mismatch.
Rust
if ($x = 97) {{}}
if ($x -eq 97) {{}}
Use -eq.
PowerShell
switch(c){{ case 8: break; }}
switch(c){{ case 8: break; default: break; }}
Add default case.
Java
if (y = 69) {{}}
if (y == 69) {{}}
Use ==.
Java
foo
foo()
Add parentheses.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
let list=vec![21,53,36]; let first=&list[0]; list.push(97);
let mut list=vec![21,53,36]; let first=list[0]; list.push(97);
Copy instead of reference.
Rust