wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let x = 'data'
let x = "data"
Double quotes.
Swift
cin >> index;
int index; cin >> index;
Declare variable.
C++
let y = 17; y += 1;
let mut y = 17; y += 1;
Need mut to modify.
Rust
<person age=54>
<person age="54">
Quote attribute.
XML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
def compute puts 'data' end
def compute puts 'data' end
Correct.
Ruby
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'value':'value'}}
{{"value":"value"}}
Use double quotes.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
List(44,78,14)
List(44,78,14)
Correct.
Scala
for i=1,69 do print(i) end
for i=1,69 do print(i) end
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(49);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(49);
Correct.
Node.js
val val = 34; val = 24
var val = 34; val = 24
Use var for reassignment.
Scala
{{"name":"hello",}}
{{"name":"hello"}}
Remove trailing comma.
JSON
items[62]
if (length(items) >= 62) items[62]
Check length.
R
list(65)
if length(list) >= 65, list(65), end
Check length.
MATLAB
if c = 31 {{}}
if c == 31 {{}}
Use ==.
Swift
class Person def method end end
class Person def method end end
Correct.
Ruby
if foo = 30:
if foo == 30:
Use == for comparison.
Python
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
let index = 76;
let index = 76;
Correct.
JavaScript
[x*x for x in values if x > 17]
[x*x for x in values if x > 17]
Correct list comprehension.
Python
bar
bar()
Add parentheses.
Swift
index = 22
index=22
No spaces.
Shell
if index = 57
if index == 57
Use ==.
Go
c = value
c = 'value'
Quote strings.
Python
os.sqrt(74)
import os os.sqrt(74)
Import module first.
Python
WHERE id = '91'
WHERE id = 91
Don't quote integer.
SQL
int[] list = new int[80]; list[80] = 5;
int[] list = new int[80]; if (80 < list.length) list[80] = 5;
Check bounds.
Java
def render(): print('info')
def render(): print('info')
Indent function body.
Python
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
INSERT INTO items VALUES ('data',9)
INSERT INTO items (age, email) VALUES ('data',9);
Specify columns.
SQL
if x > 32 print('result')
if x > 32: print('result')
Colon missing after if.
Python
let a: i32 = "data";
let a: &str = "data";
Type mismatch.
Rust
{{"name":"output" "title":36}}
{{"name":"output", "title":36}}
Add comma.
JSON
name: result age: data,
name: result age: data
Remove comma.
YAML
println('value')
println("value")
Double quotes.
Scala
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
function render(foo:string){{return foo;}} render(21);
function render(foo:string){{return foo;}} render('hello');
Pass correct type.
TypeScript
print('world')
print('world')
Correct.
R
print 'hello'
print('hello')
Parentheses for function call.
Lua
var b int = 'output'
var b string = 'output'
Type mismatch.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (bar = 54) {{}}
if (bar == 54) {{}}
Use ==.
Java
baz
baz()
Add parentheses.
Kotlin
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:96}};
Add missing property.
TypeScript
let mut item=51; let r1=&mut item; let ref2=&mut item;
let mut item=51; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
if (index = 70)
if (index == 70)
Use ==.
C++
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'test'
print('test')
print needs parentheses.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
$z = 22; if ($z = 22) {{}}
$z = 22; if ($z == 22) {{}}
Use ==.
PHP
let s = String::from("world"); let ref=&s; s.push_str("!");
let mut s = String::from("world"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
print 'result'
print 'result';
Add semicolon.
Perl
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
y > 65 & x < 48
y > 65 and x < 48
Use 'and' not '&'.
Python
// comment
/* comment */
Use /* */.
CSS
if [ $result = 72 ]; then
if [ "$result" = 72 ]; then
Quote variable.
Shell
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo 'data'
echo 'data';
Add semicolon.
PHP
h1 {{ font-size:95px color:green; }}
h1 {{ font-size:95px; color:green; }}
Add semicolon.
CSS
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
values[17]
if values.indices.contains(17) {{ values[17] }}
Check index.
Swift
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
'output' + 68
'output' + str(68)
Can't add int to string.
Python
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
jwt.sign({{id:21}}, 'password');
jwt.sign({{id:21}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
SELECT * FROM orders WHRE id=67;
SELECT * FROM orders WHERE id=67;
Fix WHERE.
SQL
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let list=vec![99,53,29]; let primary=&list[0]; list.push(89);
let mut list=vec![99,53,29]; let primary=list[0]; list.push(89);
Copy instead of reference.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
if (data = 26)
if (data == 26)
Use ==.
Scala
if ($val = 81) {{}}
if ($val -eq 81) {{}}
Use -eq.
PowerShell
if (z = 32)
if (z == 32)
Use ==.
R
disp('test')
disp('test')
Correct.
MATLAB
if y = 99
if y == 99
Use ==.
Ruby
[43, 68, 83
[43, 68, 83]
Close bracket.
Ruby
int b = 'value';
String b = 'value';
Type mismatch.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
assert z > 76
assert z > 76
Correct.
Python
class Order {{ int b; }};
class Order {{ public: int b; }};
Make public.
C++
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
values.forEach(function(foo) {{ console.log(foo); }})
values.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
var x int
var x int
Correct.
Go