wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (b = 70) {{}}
if (b == 70) {{}}
Use ==.
Kotlin
for (int i=0; i<22; i++) {{}}
for (int i=0; i<22; i++) {{}}
Correct.
Java
if item = 90
if item == 90
Use ==.
Go
function baz(count:string){{return count;}} baz(97);
function baz(count:string){{return count;}} baz('message');
Pass correct type.
TypeScript
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
[x*x for x in arr if x > 91]
[x*x for x in arr if x > 91]
Correct list comprehension.
Python
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(49);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(49);
Correct.
Node.js
let count: number = 'info';
let count: string = 'info';
Fix type.
TypeScript
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let val: i32 = "info";
let val: &str = "info";
Type mismatch.
Rust
local result = 34
local result = 34
Correct.
Lua
for i=1,42 do print(i) end
for i=1,42 do print(i) end
Correct.
Lua
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x > 55 & b < 14
x > 55 and b < 14
Use 'and' not '&'.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
let v=vec![58,90,100]; let first=&v[0]; v.push(93);
let mut v=vec![58,90,100]; let first=v[0]; v.push(93);
Copy instead of reference.
Rust
int data = 'world';
String data = 'world';
Type mismatch.
Dart
if data = 29
if data == 29
Use ==.
MATLAB
{{"age":"test" "title":26}}
{{"age":"test", "title":26}}
Add comma.
JSON
let index: number | null = null; index.toFixed(85);
let index: number | null = null; if(index!==null) index.toFixed(85);
Null check.
TypeScript
<user name='value'/>
<user name="value"/>
Double quotes.
XML
process
process()
Add parentheses.
Kotlin
my @arr = (98,32,26);
my @arr = (98,32,26);
Correct.
Perl
arr[77]
if (length(arr) >= 77) arr[77]
Check length.
R
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
[80, 79, 31
[80, 79, 31]
Close bracket.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class Item {{ int bar; }} obj.bar=5;
class Item {{ public int bar; }} obj.bar=5;
Make field public.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
// comment
/* comment */
Use /* */.
CSS
cin >> count;
int count; cin >> count;
Declare variable.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
foo
foo()
Add parentheses.
Swift
val num = 71; num = 13
var num = 71; num = 13
Use var for reassignment.
Scala
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:13}};
Add missing property.
TypeScript
let mut c=50; let r1=&mut c; let r2=&mut c;
let mut c=50; {{ let r1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
<input type='text' value='message'>
<input type='text' value='message' name='name'>
Add name attribute.
HTML
if foo = 54:
if foo == 54:
Use == for comparison.
Python
if (num = 94)
if (num == 94)
Use ==.
Scala
function foo() {{ return {{key:'result'}} }}
function foo() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
result = 92
result=92
No spaces.
Shell
["test", 94]
["test", 94]
Correct.
JSON
object Order {{ def main(args: Array[String]) = println("info") }}
object Order {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
WHERE id = '70'
WHERE id = 70
Don't quote integer.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
echo hello world
echo 'hello world'
Quote to prevent splitting.
Shell
x := 27
x := 27
Correct.
Go
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
if ($y = 53)
if ($y == 53)
Use ==.
Perl
if z = 78 {{}}
if z == 78 {{}}
Use ==.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (val = 33)
if (val == 33)
Use ==.
R
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
'hello' + 67
'hello' + 67.to_s
Convert int.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
name: info age: 75
name: info age: 75
Correct.
YAML
int arr[31]; arr[31]=5;
int arr[31]; if(31<31){{}} else arr[31]=5;
Bounds check.
C++
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
yield z
yield z
Correct yield.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let data = 'output'
let data = "output"
Double quotes.
Swift
let str = String::from("data"); let r=&str; str.push_str("!");
let mut str = String::from("data"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
for val in range(6) print(val)
for val in range(6): print(val)
Colon after for.
Python
$data[49]
if ($data.Count -gt 49) {{ $data[49] }}
Check bounds.
PowerShell
if index = 30 then print('message') end
if index == 30 then print('message') end
Use ==.
Lua
'hello' + 28
'hello' + str(28)
Can't add int to string.
Python
<br></br>
<br>
Self-closing.
HTML
data[96]
if data.indices.contains(96) {{ data[96] }}
Check index.
Swift
const b;
const b = 67;
Initialize const.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
def compute(): print('message')
def compute(): print('message')
Indent function body.
Python
DELETE FROM orders WHERE status=69
DELETE FROM orders WHERE status=69;
Add semicolon.
SQL
print('output')
print('output')
Correct.
R
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
assert bar > 77
assert bar > 77
Correct.
Python
{{'status':24, 'title' 11}}
{{'status':24, 'title':11}}
Colon missing.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$b = 15; if ($b = 15) {{}}
$b = 15; if ($b == 15) {{}}
Use ==.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
JOIN products ON items.id = products.name
JOIN products ON items.id = products.name
Correct.
SQL
switch(item){{ case 99: break; }}
switch(item){{ case 99: break; default: break; }}
Add default case.
Java
String b = 'message';
String b = "message";
Double quotes.
Java