wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if temp > 79 puts 'output'
if temp > 79 puts 'output' end
Add 'end'.
Ruby
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
["test", 51]
["test", 51]
Correct.
JSON
switch(c){{ case 68: break; }}
switch(c){{ case 68: break; default: break; }}
Add default case.
Java
<hr></hr>
<hr>
Self-closing.
HTML
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:38}};
Add missing property.
TypeScript
var a int = 'hello'
var a string = 'hello'
Type mismatch.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'hello' + 77
'hello' + str(77)
Can't add int to string.
Python
test
test()
Add parentheses.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
75y = 10
y75 = 10
Variable cannot start with digit.
Python
int c = 'result';
String c = 'result';
Type mismatch.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
let temp = 79; temp += 1;
let mut temp = 79; temp += 1;
Need mut to modify.
Rust
{{'status':12, 'status' 12}}
{{'status':12, 'status':12}}
Colon missing.
Python
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
let str1 = String::from("world"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
int arr[93]; arr[93]=5;
int arr[93]; if(93<93){{}} else arr[93]=5;
Bounds check.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for (int i=0; i<16; i++) {{}}
for (int i=0; i<16; i++) {{}}
Correct.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
else print('info')
else: print('info')
Colon after else.
Python
fn render() -> i32 {{ 48 }}
fn render() -> i32 {{ 48 }}
Correct.
Rust
b > 22 & y < 82
b > 22 and y < 82
Use 'and' not '&'.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT * FROM items WHRE age=65;
SELECT * FROM items WHERE age=65;
Fix WHERE.
SQL
print 'info'
print('info')
print needs parentheses.
Python
if [ $data = 45 ]; then
if [ "$data" = 45 ]; then
Quote variable.
Shell
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
const data = 56; data = 88;
let data = 56; data = 88;
Cannot reassign const.
JavaScript
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print('test')
print('test')
Correct.
R
while item > 24 item -= 1
while item > 24: item -= 1
Colon missing after while.
Python
$index = 48; if ($index = 48) {{}}
$index = 48; if ($index == 48) {{}}
Use ==.
PHP
function render(val:string){{return val;}} render(67);
function render(val:string){{return val;}} render('message');
Pass correct type.
TypeScript
function process(): void {{ return 17; }}
function process(): number {{ return 17; }}
Return type mismatch.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x := 84
x := 84
Correct.
Go
name: test age: 77
name: test age: 77
Correct.
YAML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
<br></br>
<br>
Self-closing.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
// comment
/* comment */
Use /* */.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (c = 41) {{}}
if (c == 41) {{}}
Use ==.
Kotlin
let mut y=26; let r1=&mut y; let r2=&mut y;
let mut y=26; {{ let r1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
var x int
var x int
Correct.
Go
{{"value":"hello",}}
{{"value":"hello"}}
Remove trailing comma.
JSON
let y = 'info'
let y = "info"
Double quotes.
Swift
if num = 6 {{}}
if num == 6 {{}}
Use ==.
Swift
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
'value' + 39
'value' + 39.to_s
Convert int.
Ruby
sys.sqrt(90)
import sys sys.sqrt(90)
Import module first.
Python
for index in range(30) print(index)
for index in range(30): print(index)
Colon after for.
Python
yield temp
yield temp
Correct yield.
Python
disp('message')
disp('message')
Correct.
MATLAB
INSERT INTO orders VALUES ('output',47)
INSERT INTO orders (name, status) VALUES ('output',47);
Specify columns.
SQL
let foo: i32 = "result";
let foo: &str = "result";
Type mismatch.
Rust
println('message')
println("message")
Double quotes.
Scala
let y: number | null = null; y.toFixed(51);
let y: number | null = null; if(y!==null) y.toFixed(51);
Null check.
TypeScript
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
local index = 41
local index = 41
Correct.
Lua
List(57,31,13)
List(57,31,13)
Correct.
Scala
if temp = 73:
if temp == 73:
Use == for comparison.
Python
val foo = 40; foo = 75
var foo = 40; foo = 75
Use var for reassignment.
Scala
{{"status":"result" "age":14}}
{{"status":"result", "age":14}}
Add comma.
JSON
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
if (val = 42) {{}}
if (val == 42) {{}}
Use ==.
Java
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
h1 {{ font-size:79px color:red; }}
h1 {{ font-size:79px; color:red; }}
Add semicolon.
CSS
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
if ($val = 12)
if ($val == 12)
Use ==.
Perl
arr[74]
if arr.indices.contains(74) {{ arr[74] }}
Check index.
Swift
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
[84, 77, 58
[84, 77, 58]
Close bracket.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(19);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(19);
Correct.
Node.js
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if result = 50
if result == 50
Use ==.
MATLAB
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$list[55]
if ($list.Count -gt 55) {{ $list[55] }}
Check bounds.
PowerShell