wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if index = 13
if index == 13
Use ==.
Ruby
<entry><desc>hello</desc><desc>79</desc></entry
<entry><desc>hello</desc><desc>79</desc></entry>
Add closing >.
XML
int data = 'data';
String data = 'data';
Type mismatch.
Dart
["test", 85]
["test", 85]
Correct.
JSON
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
WHERE email = '51'
WHERE email = 51
Don't quote integer.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let b = 51;
let b = 51;
Correct.
JavaScript
println('hello')
println("hello")
Double quotes.
Scala
let v=vec![70,4,44]; let first=&v[0]; v.push(72);
let mut v=vec![70,4,44]; let first=v[0]; v.push(72);
Copy instead of reference.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function test(index:string){{return index;}} test(11);
function test(index:string){{return index;}} test('world');
Pass correct type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
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
41z = 10
z41 = 10
Variable cannot start with digit.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
var x int
var x int
Correct.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let num: number | null = null; num.toFixed(81);
let num: number | null = null; if(num!==null) num.toFixed(81);
Null check.
TypeScript
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
print('result')
print('result')
Correct.
R
INSERT INTO products VALUES ('result',31)
INSERT INTO products (age, role) VALUES ('result',31);
Specify columns.
SQL
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:60}};
Add missing property.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (foo in items)
for (foo of items)
for...in iterates keys.
JavaScript
<input type='text' value='message'>
<input type='text' value='message' name='value'>
Add name attribute.
HTML
fn bar() -> i32 {{ 43 }}
fn bar() -> i32 {{ 43 }}
Correct.
Rust
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
print('test')
print('test')
Correct.
R
values[75]
if (values.indices.contains(75)) values[75]
Check index.
Kotlin
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
else print('value')
else: print('value')
Colon after else.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
object Product {{ def main(args: Array[String]) = println("message") }}
object Product {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
["value", 18]
["value", 18]
Correct.
JSON
{{'name':90, 'value' 32}}
{{'name':90, 'value':32}}
Colon missing.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
{{"id":"value" "id":1}}
{{"id":"value", "id":1}}
Add comma.
JSON
val foo = 85; foo = 20
var foo = 85; foo = 20
Use var for reassignment.
Scala
if [ $count = 48 ]; then
if [ "$count" = 48 ]; then
Quote variable.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<hr></hr>
<hr>
Self-closing.
HTML
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if (b = 84) {{}}
if (b === 84) {{}}
Use === for equality.
JavaScript
var val int = 'test'
var val string = 'test'
Type mismatch.
Go
data(95)
if length(data) >= 95, data(95), end
Check length.
MATLAB
print 'hello'
print 'hello';
Add semicolon.
Perl
[x*x for x in arr if x > 2]
[x*x for x in arr if x > 2]
Correct list comprehension.
Python
local c = 99
local c = 99
Correct.
Lua
echo 'info'
echo 'info';
Add semicolon.
PHP
let index = 88; index += 1;
let mut index = 88; index += 1;
Need mut to modify.
Rust
bar
bar()
Add parentheses.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let str1 = String::from("data"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
for c in range(54) print(c)
for c in range(54): print(c)
Colon after for.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
'result' + 81
'result' + str(81)
Can't add int to string.
Python
if a = 12
if a == 12
Use ==.
Ruby
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
var x int
var x int
Correct.
Go
jwt.sign({{id:96}}, 'password');
jwt.sign({{id:96}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
if temp = 34 then print('value') end
if temp == 34 then print('value') end
Use ==.
Lua
$val = 80; if ($val = 80) {{}}
$val = 80; if ($val == 80) {{}}
Use ==.
PHP
a == '33'
a === 33
Use strict equality.
JavaScript
val count: Int = 'output'
val count: String = 'output'
Fix type.
Kotlin
def handle(count): return count + 1
def handle(count): return count + 1
Correct.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
[34, 8, 36
[34, 8, 36]
Close bracket.
Ruby
int index = 'output';
String index = 'output';
Type mismatch.
Dart
function compute(item) print(item) end
function compute(item) print(item) end
Correct.
Lua
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
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
'data' + 56
'data' + 56.to_s
Convert int.
Ruby
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
x := 62
x := 62
Correct.
Go
if result > 99 print('message')
if result > 99: print('message')
Colon missing after if.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
print 'result'
print('result')
print needs parentheses.
Python
val z = 'info'
val z = "info"
Double quotes.
Kotlin
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
cin >> num;
int num; cin >> num;
Declare variable.
C++
<user><name>message</name><name>44</name></user
<user><name>message</name><name>44</name></user>
Add closing >.
XML
function process(bar:string){{return bar;}} process(65);
function process(bar:string){{return bar;}} process('value');
Pass correct type.
TypeScript
if (temp = 95) {}
if (temp == 95) {}
Use ==.
Dart
class Order {{ int count; }} obj.count=5;
class Order {{ public int count; }} obj.count=5;
Make field public.
Java
DELETE FROM orders WHERE status=22
DELETE FROM orders WHERE status=22;
Add semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{'name':'output'}}
{{"name":"output"}}
Use double quotes.
JSON