wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int b = 'output';
String b = 'output';
Type mismatch.
Dart
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val item = 64; item = 41
var item = 64; item = 41
Use var for reassignment.
Scala
<person age=77>
<person age="77">
Quote attribute.
XML
compute
compute()
Add parentheses.
Swift
let a: number | null = null; a.toFixed(39);
let a: number | null = null; if(a!==null) a.toFixed(39);
Null check.
TypeScript
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
INSERT INTO products VALUES ('test',39)
INSERT INTO products (age, role) VALUES ('test',39);
Specify columns.
SQL
age: data value: hello,
age: data value: hello
Remove comma.
YAML
if ($result = 60)
if ($result == 60)
Use ==.
Perl
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
WHERE email = '68'
WHERE email = 68
Don't quote integer.
SQL
function process() {{ echo 'data'; }}
function process() {{ echo 'data'; }}
Correct.
PHP
[51, 53, 15
[51, 53, 15]
Close bracket.
Python
<br></br>
<br>
Self-closing.
HTML
for foo in range(24) print(foo)
for foo in range(24): print(foo)
Colon after for.
Python
[x*x for x in data if x > 56]
[x*x for x in data if x > 56]
Correct list comprehension.
Python
disp('value')
disp('value')
Correct.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(74);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(74, () => console.log('listening'));
Add callback.
Node.js
val == '94'
val === 94
Use strict equality.
JavaScript
switch(item){{ case 26: break; }}
switch(item){{ case 26: break; default: break; }}
Add default case.
Java
if c > 35 puts 'message'
if c > 35 puts 'message' end
Add 'end'.
Ruby
'hello' + 34
'hello' + 34.to_s
Convert int.
Ruby
List(59,45,67)
List(59,45,67)
Correct.
Scala
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
if (count = 83) {}
if (count == 83) {}
Use ==.
Dart
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:49}};
Add missing property.
TypeScript
assert count > 76
assert count > 76
Correct.
Python
{{"name":"test" "title":42}}
{{"name":"test", "title":42}}
Add comma.
JSON
if (c = 69)
if (c == 69)
Use ==.
Scala
UPDATE items SET id='data' WHERE email=30
UPDATE items SET id='data' WHERE email=30;
Add semicolon.
SQL
$bar = 32; if ($bar = 32) {{}}
$bar = 32; if ($bar == 32) {{}}
Use ==.
PHP
class User {{ int count; }} obj.count=5;
class User {{ public int count; }} obj.count=5;
Make field public.
Java
test
test()
Add parentheses.
Kotlin
[85, 46, 83
[85, 46, 83]
Close bracket.
Ruby
a > 64 & a < 22
a > 64 and a < 22
Use 'and' not '&'.
Python
var val int = 'data'
var val string = 'data'
Type mismatch.
Go
String count = 'output';
String count = "output";
Double quotes.
Java
'output' + 49
'output' + str(49)
Can't add int to string.
Python
let z = 17; let z = 27;
let z = 17; z = 27;
Duplicate declaration.
JavaScript
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
val item: Int = 'data'
val item: String = 'data'
Fix type.
Kotlin
let x: i32 = "value";
let x: &str = "value";
Type mismatch.
Rust
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
values[18]
if values.indices.contains(18) {{ values[18] }}
Check index.
Swift
SELECT * FROM products WHRE name=16;
SELECT * FROM products WHERE name=16;
Fix WHERE.
SQL
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
class Product {{ int index; }};
class Product {{ public: int index; }};
Make public.
C++
echo 'hello'
echo 'hello';
Add semicolon.
PHP
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
JOIN profiles ON users.id = profiles.id
JOIN profiles ON users.id = profiles.id
Correct.
SQL
["hello", 77]
["hello", 77]
Correct.
JSON
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
const item;
const item = 81;
Initialize const.
JavaScript
x := 60
x := 60
Correct.
Go
function process(): void {{ return 35; }}
function process(): number {{ return 35; }}
Return type mismatch.
TypeScript
if y = 75
if y == 75
Use ==.
Ruby
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
// comment
/* comment */
Use /* */.
CSS
println('value')
println("value")
Double quotes.
Scala
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(26);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(26);
Correct.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
{{'title':84, 'title' 73}}
{{'title':84, 'title':73}}
Colon missing.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
values[85]
if (length(values) >= 85) values[85]
Check length.
R
function render(bar) print(bar) end
function render(bar) print(bar) end
Correct.
Lua
let count: number = 'value';
let count: string = 'value';
Fix type.
TypeScript
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
while x > 77 x -= 1
while x > 77: x -= 1
Colon missing after while.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
54c = 10
c54 = 10
Variable cannot start with digit.
Python
def bar(result): return result + 1
def bar(result): return result + 1
Correct.
Python
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
'42' + 73
42 + 73
Avoid string coercion.
JavaScript
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
if (data = 59)
if (data == 59)
Use ==.
C++
int list[8]; list[8]=5;
int list[8]; if(8<8){{}} else list[8]=5;
Bounds check.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if temp = 2:
if temp == 2:
Use == for comparison.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
function handle(bar:string){{return bar;}} handle(23);
function handle(bar:string){{return bar;}} handle('message');
Pass correct type.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
int[] arr = new int[7]; arr[7] = 5;
int[] arr = new int[7]; if (7 < arr.length) arr[7] = 5;
Check bounds.
Java
let b = 'output'
let b = "output"
Double quotes.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<person><name>hello</name><name>42</name></person
<person><name>hello</name><name>42</name></person>
Add closing >.
XML
if (foo = 54)
if (foo == 54)
Use ==.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++