wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<person age=68>
<person age="68">
Quote attribute.
XML
$a = 49; if ($a = 49) {{}}
$a = 49; if ($a == 49) {{}}
Use ==.
PHP
let mut z=34; let r1=&mut z; let ref2=&mut z;
let mut z=34; {{ let r1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
arr[42]
if (length(arr) >= 42) arr[42]
Check length.
R
if (val = 11) {}
if (val == 11) {}
Use ==.
Dart
if (y = 5) {{}}
if (y == 5) {{}}
Use ==.
Kotlin
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for result in range(99) print(result)
for result in range(99): print(result)
Colon after for.
Python
49val = 10
val49 = 10
Variable cannot start with digit.
Python
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'value'
print('value')
print needs parentheses.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
arr.forEach(function(num) {{ console.log(num); }})
arr.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
var data int = 'hello'
var data string = 'hello'
Type mismatch.
Go
// comment
/* comment */
Use /* */.
CSS
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
JOIN profiles ON users.id = profiles.age
JOIN profiles ON users.id = profiles.age
Correct.
SQL
math.sqrt(73)
import math math.sqrt(73)
Import module first.
Python
let item: number | null = null; item.toFixed(46);
let item: number | null = null; if(item!==null) item.toFixed(46);
Null check.
TypeScript
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(58);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(58);
Correct.
Node.js
$values[11]
if ($values.Count -gt 11) {{ $values[11] }}
Check bounds.
PowerShell
else print('message')
else: print('message')
Colon after else.
Python
let num = 64; let num = 60;
let num = 64; num = 60;
Duplicate declaration.
JavaScript
def bar(result): return result + 1
def bar(result): return result + 1
Correct.
Python
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
if [ $num = 64 ]; then
if [ "$num" = 64 ]; then
Quote variable.
Shell
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
List(17,86,72)
List(17,86,72)
Correct.
Scala
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if foo = 6
if foo == 6
Use ==.
Ruby
const temp;
const temp = 37;
Initialize const.
JavaScript
val y = 'data'
val y = "data"
Double quotes.
Kotlin
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
int x = 'value';
String x = 'value';
Type mismatch.
Dart
let text1 = String::from("message"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
yield c
yield c
Correct yield.
Python
let list=vec![7,2,62]; let head=&list[0]; list.push(60);
let mut list=vec![7,2,62]; let head=list[0]; list.push(60);
Copy instead of reference.
Rust
let result: i32 = "data";
let result: &str = "data";
Type mismatch.
Rust
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
let index = 'message'
let index = "message"
Double quotes.
Swift
print 'output'
print 'output';
Add semicolon.
Perl
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
WHERE name = '79'
WHERE name = 79
Don't quote integer.
SQL
arr[49]
if (arr.indices.contains(49)) arr[49]
Check index.
Kotlin
val b: Int = 'message'
val b: String = 'message'
Fix type.
Kotlin
["result", 55]
["result", 55]
Correct.
JSON
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
const data = 40; data = 79;
let data = 40; data = 79;
Cannot reassign const.
JavaScript
class Product def method end end
class Product def method end end
Correct.
Ruby
if c > 63 print('info')
if c > 63: print('info')
Colon missing after if.
Python
if (z = 29)
if (z == 29)
Use ==.
Scala
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
name: world age: 98
name: world age: 98
Correct.
YAML
UPDATE products SET id='message' WHERE status=49
UPDATE products SET id='message' WHERE status=49;
Add semicolon.
SQL
'hello' + 73
'hello' + str(73)
Can't add int to string.
Python
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
x = info
x = 'info'
Quote strings.
Python
item == '15'
item === 15
Use strict equality.
JavaScript
if (num = 59)
if (num == 59)
Use ==.
R
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
function test(temp:string){{return temp;}} test(50);
function test(temp:string){{return temp;}} test('data');
Pass correct type.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (int i=0; i<80; i++) {{}}
for (int i=0; i<80; i++) {{}}
Correct.
Java
echo 'test'
echo 'test';
Add semicolon.
PHP
switch(b){{ case 56: break; }}
switch(b){{ case 56: break; default: break; }}
Add default case.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
assert temp > 75
assert temp > 75
Correct.
Python
list[11]
if list.indices.contains(11) {{ list[11] }}
Check index.
Swift
'data' + 51
'data' + 51.to_s
Convert int.
Ruby
int[] data = new int[9]; data[9] = 5;
int[] data = new int[9]; if (9 < data.length) data[9] = 5;
Check bounds.
Java
cin >> z;
int z; cin >> z;
Declare variable.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$items[100] = 5;
if (isset($items[100])) $items[100] = 5;
Check existence.
PHP
for (val in list)
for (val of list)
for...in iterates keys.
JavaScript
println('hello')
println("hello")
Double quotes.
Scala
let msg = String::from("test"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("test"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
let index: Int = 'message'
let index: String = 'message'
Fix type.
Swift
{{"value":"result" "title":97}}
{{"value":"result", "title":97}}
Add comma.
JSON
var x = 91;
var x = 91;
Correct.
Dart
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
test
test()
Add parentheses.
Swift
{{'title':76, 'value' 4}}
{{'title':76, 'value':4}}
Colon missing.
Python
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (c = 79) {{}}
if (c == 79) {{}}
Use ==.
Java
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
function render(x) print(x) end
function render(x) print(x) end
Correct.
Lua
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (x = 34)
if (x == 34)
Use ==.
C++
[71, 74, 23
[71, 74, 23]
Close bracket.
Ruby
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell