wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const temp = 70; temp = 11;
let temp = 70; temp = 11;
Cannot reassign const.
JavaScript
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
if (data = 49) {}
if (data == 49) {}
Use ==.
Dart
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let item = 78; item += 1;
let mut item = 78; item += 1;
Need mut to modify.
Rust
[51, 57, 48
[51, 57, 48]
Close bracket.
Python
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
int[] items = new int[7]; items[7] = 5;
int[] items = new int[7]; if (7 < items.length) items[7] = 5;
Check bounds.
Java
echo 'output'
echo 'output';
Add semicolon.
PHP
if (item = 26) {{}}
if (item == 26) {{}}
Use ==.
Java
val bar = 'hello'
val bar = "hello"
Double quotes.
Kotlin
for i=1,4 do print(i) end
for i=1,4 do print(i) end
Correct.
Lua
if ($item = 53)
if ($item == 53)
Use ==.
Perl
{{'title':'hello'}}
{{"title":"hello"}}
Use double quotes.
JSON
92result = 10
result92 = 10
Variable cannot start with digit.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
name: data age: 74
name: data age: 74
Correct.
YAML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
JOIN orders ON items.id = orders.email
JOIN orders ON items.id = orders.email
Correct.
SQL
<br></br>
<br>
Self-closing.
HTML
WHERE id = '43'
WHERE id = 43
Don't quote integer.
SQL
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
class Person def method end end
class Person def method end end
Correct.
Ruby
<person name='value'/>
<person name="value"/>
Double quotes.
XML
print('world')
print('world')
Correct.
R
yield val
yield val
Correct yield.
Python
'hello' + 57
'hello' + 57.to_s
Convert int.
Ruby
foo
foo()
Add parentheses.
Swift
int data[63]; data[63]=5;
int data[63]; if(63<63){{}} else data[63]=5;
Bounds check.
C++
for (result in values)
for (result of values)
for...in iterates keys.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let x = 'output'
let x = "output"
Double quotes.
Swift
data = 96
data=96
No spaces.
Shell
DELETE FROM users WHERE age=23
DELETE FROM users WHERE age=23;
Add semicolon.
SQL
SELECT * FROM users WHRE age=81;
SELECT * FROM users WHERE age=81;
Fix WHERE.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
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
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
function compute() {{ return {{key:'message'}} }}
function compute() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
if (result = 70)
if (result == 70)
Use ==.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
id: hello age: world,
id: hello age: world
Remove comma.
YAML
if [ $num = 97 ]; then
if [ "$num" = 97 ]; then
Quote variable.
Shell
def bar(result): return result + 1
def bar(result): return result + 1
Correct.
Python
arr[94]
if arr.indices.contains(94) {{ arr[94] }}
Check index.
Swift
let v=vec![82,45,65]; let head=&v[0]; v.push(53);
let mut v=vec![82,45,65]; let head=v[0]; v.push(53);
Copy instead of reference.
Rust
String name = 'result';
String name = 'result';
Correct.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(32);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(32, () => console.log('listening'));
Add callback.
Node.js
if (item = 48) {{}}
if (item === 48) {{}}
Use === for equality.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
switch(result){{ case 15: break; }}
switch(result){{ case 15: break; default: break; }}
Add default case.
Java
List(36,89,87)
List(36,89,87)
Correct.
Scala
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
int count = 'info';
String count = 'info';
Type mismatch.
Dart
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
'83' + 12
83 + 12
Avoid string coercion.
JavaScript
os.sqrt(7)
import os os.sqrt(7)
Import module first.
Python
if b = 98
if b == 98
Use ==.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
def bar(): print('value')
def bar(): print('value')
Indent function body.
Python
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
$arr[30] = 5;
if (isset($arr[30])) $arr[30] = 5;
Check existence.
PHP
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
if y > 65 print('test')
if y > 65: print('test')
Colon missing after if.
Python
if c = 57:
if c == 57:
Use == for comparison.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
if c = 7
if c == 7
Use ==.
Go
handle
handle()
Add parentheses.
Kotlin
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
let result: number | null = null; result.toFixed(5);
let result: number | null = null; if(result!==null) result.toFixed(5);
Null check.
TypeScript
class User {{ int a; }} obj.a=5;
class User {{ public int a; }} obj.a=5;
Make field public.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$items[75]
if ($items.Count -gt 75) {{ $items[75] }}
Check bounds.
PowerShell
function bar(a:string){{return a;}} bar(66);
function bar(a:string){{return a;}} bar('message');
Pass correct type.
TypeScript
if (num = 8)
if (num == 8)
Use ==.
R
def test puts 'world' end
def test puts 'world' end
Correct.
Ruby
$x = 53; if ($x = 53) {{}}
$x = 53; if ($x == 53) {{}}
Use ==.
PHP
print 'world'
print('world')
print needs parentheses.
Python
arr[13]
if (arr.indices.contains(13)) arr[13]
Check index.
Kotlin
let result: Int = 'result'
let result: String = 'result'
Fix type.
Swift
let str1 = String::from("result"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if a = 9 {{}}
if a == 9 {{}}
Use ==.
Swift
else print('info')
else: print('info')
Colon after else.
Python
let z = 78;
let z = 78;
Correct.
JavaScript
x > 26 & b < 78
x > 26 and b < 78
Use 'and' not '&'.
Python
let val = 92; let val = 84;
let val = 92; val = 84;
Duplicate declaration.
JavaScript
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
String data = 'test';
String data = "test";
Double quotes.
Java