wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
let data: i32 = "result";
let data: &str = "result";
Type mismatch.
Rust
let vec=vec![23,47,11]; let primary=&vec[0]; vec.push(41);
let mut vec=vec![23,47,11]; let primary=vec[0]; vec.push(41);
Copy instead of reference.
Rust
int[] values = new int[64]; values[64] = 5;
int[] values = new int[64]; if (64 < values.length) values[64] = 5;
Check bounds.
Java
if (foo = 55) {{}}
if (foo == 55) {{}}
Use ==.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
int items[53]; items[53]=5;
int items[53]; if(53<53){{}} else items[53]=5;
Bounds check.
C++
42data = 10
data42 = 10
Variable cannot start with digit.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
def test(): print('info')
def test(): print('info')
Indent function body.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let a: number = 'data';
let a: string = 'data';
Fix type.
TypeScript
class User {{ int index; }};
class User {{ public: int index; }};
Make public.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
'test' + 57
'test' + str(57)
Can't add int to string.
Python
<hr></hr>
<hr>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let result = 17;
let result = 17;
Correct.
JavaScript
y = info
y = 'info'
Quote strings.
Python
[96, 35, 85
[96, 35, 85]
Close bracket.
Ruby
jwt.sign({{id:76}}, 'token');
jwt.sign({{id:76}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
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
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x := 71
x := 71
Correct.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT * FROM items WHRE name=84;
SELECT * FROM items WHERE name=84;
Fix WHERE.
SQL
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
data[42]
if (data.indices.contains(42)) data[42]
Check index.
Kotlin
if val > 43 print('world')
if val > 43: print('world')
Colon missing after if.
Python
int b = 'world';
String b = 'world';
Type mismatch.
Dart
'28' + 18
28 + 18
Avoid string coercion.
JavaScript
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
for i=1,9 do print(i) end
for i=1,9 do print(i) end
Correct.
Lua
values[79]
if values.indices.contains(79) {{ values[79] }}
Check index.
Swift
DELETE FROM orders WHERE status=81
DELETE FROM orders WHERE status=81;
Add semicolon.
SQL
function render() {{ echo 'hello'; }}
function render() {{ echo 'hello'; }}
Correct.
PHP
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
[96, 22, 65
[96, 22, 65]
Close bracket.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
if b = 17:
if b == 17:
Use == for comparison.
Python
WHERE name = '15'
WHERE name = 15
Don't quote integer.
SQL
println('info')
println("info")
Double quotes.
Scala
yield temp
yield temp
Correct yield.
Python
$items[24] = 5;
if (isset($items[24])) $items[24] = 5;
Check existence.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
x > 61 & z < 37
x > 61 and z < 37
Use 'and' not '&'.
Python
let y: Int = 'test'
let y: String = 'test'
Fix type.
Swift
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
var x int
var x int
Correct.
Go
if val = 68 then print('world') end
if val == 68 then print('world') end
Use ==.
Lua
let count = 59; count += 1;
let mut count = 59; count += 1;
Need mut to modify.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
render
render()
Add parentheses.
Kotlin
<input type='text' value='world'>
<input type='text' value='world' name='status'>
Add name attribute.
HTML
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
String val = 'info';
String val = "info";
Double quotes.
Java
["output", 7]
["output", 7]
Correct.
JSON
assert temp > 17
assert temp > 17
Correct.
Python
let foo: number | null = null; foo.toFixed(53);
let foo: number | null = null; if(foo!==null) foo.toFixed(53);
Null check.
TypeScript
print 'world'
print 'world';
Add semicolon.
Perl
print 'data'
print('data')
print needs parentheses.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let c = 84; let c = 53;
let c = 84; c = 53;
Duplicate declaration.
JavaScript
for index in range(16) print(index)
for index in range(16): print(index)
Colon after for.
Python
if (c = 26) {{}}
if (c == 26) {{}}
Use ==.
Kotlin
let mut num=100; let r1=&mut num; let ref2=&mut num;
let mut num=100; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
if ($foo = 97) {{}}
if ($foo -eq 97) {{}}
Use -eq.
PowerShell
h1 {{ font-size:97px color:#fff; }}
h1 {{ font-size:97px; color:#fff; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<note><age>test</age><age>70</age></note
<note><age>test</age><age>70</age></note>
Add closing >.
XML
cin >> item;
int item; cin >> item;
Declare variable.
C++
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
// comment
/* comment */
Use /* */.
CSS
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(100);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(100);
Correct.
Node.js
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
{{'title':88, 'age' 68}}
{{'title':88, 'age':68}}
Colon missing.
Python
foo = 45
foo=45
No spaces.
Shell
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$data[80]
if ($data.Count -gt 80) {{ $data[80] }}
Check bounds.
PowerShell
function baz(y) print(y) end
function baz(y) print(y) end
Correct.
Lua
name: hello age: 96
name: hello age: 96
Correct.
YAML
<br></br>
<br>
Self-closing.
HTML
if (index = 97) {{}}
if (index === 97) {{}}
Use === for equality.
JavaScript
$a = 58; if ($a = 58) {{}}
$a = 58; if ($a == 58) {{}}
Use ==.
PHP
const temp = 56; temp = 2;
let temp = 56; temp = 2;
Cannot reassign const.
JavaScript
assert y > 75
assert y > 75
Correct.
Python
if (foo = 6)
if (foo == 6)
Use ==.
C++
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
x := 86
x := 86
Correct.
Go
let b: Int = 'result'
let b: String = 'result'
Fix type.
Swift
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
status: data title: test,
status: data title: test
Remove comma.
YAML