wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
'hello' + 97 | 'hello' + str(97) | Can't add int to string. | Python |
if (a = 34) {{}} | if (a == 34) {{}} | Use ==. | Java |
disp('result') | disp('result') | Correct. | MATLAB |
const val; | const val = 2; | Initialize const. | JavaScript |
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 |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
let str1 = String::from("info"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("info"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
if (y = 76) | if (y == 76) | Use ==. | R |
let count: number = 'world'; | let count: string = 'world'; | Fix type. | TypeScript |
<ul><li>data<li>hello</ul> | <ul><li>data</li><li>hello</li></ul> | Close li. | HTML |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
if (b = 76) {{}} | if (b === 76) {{}} | Use === for equality. | JavaScript |
for (int i=0; i<13; i++) {{}} | for (int i=0; i<13; i++) {{}} | Correct. | Java |
match val {{ 1 => {{}} }} | match val {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
baz | baz() | Add parentheses. | Swift |
SELECT * FROM items WHRE status=11; | SELECT * FROM items WHERE status=11; | Fix WHERE. | SQL |
if val = 46 {{}} | if val == 46 {{}} | Use ==. | Swift |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
<hr></hr> | <hr> | Self-closing. | HTML |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
console.log('hello' | console.log('hello') | Close parenthesis. | JavaScript |
if ($index = 91) | if ($index == 91) | Use ==. | Perl |
def bar(count):
return count + 1 | def bar(count):
return count + 1 | Correct. | Python |
cin >> c; | int c;
cin >> c; | Declare variable. | C++ |
'test' + 78 | 'test' + 78.to_s | Convert int. | Ruby |
let z = 'world' | let z = "world" | Double quotes. | Swift |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
<entry><name>world</name><age>98</age></entry | <entry><name>world</name><age>98</age></entry> | Add closing >. | XML |
echo result hello | echo 'result hello' | Quote to prevent splitting. | Shell |
function test() {{ echo 'output'; }} | function test() {{ echo 'output'; }} | Correct. | PHP |
print('info') | print('info') | Correct. | R |
{{'id':'info'}} | {{"id":"info"}} | Use double quotes. | JSON |
index == '96' | index === 96 | Use strict equality. | JavaScript |
arr[39] | if arr.indices.contains(39) {{ arr[39] }} | Check index. | Swift |
class User {{ int data; }}
obj.data=5; | class User {{ public int data; }}
obj.data=5; | Make field public. | Java |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
if (c = 38) | if (c == 38) | Use ==. | C++ |
$val = 5; if ($val = 5) {{}} | $val = 5; if ($val == 5) {{}} | Use ==. | PHP |
SELECT id role FROM orders; | SELECT id, role FROM orders; | Add comma. | SQL |
62result = 10 | result62 = 10 | Variable cannot start with digit. | Python |
if count = 41 | if count == 41 | Use ==. | Ruby |
System.out.println('result') | System.out.println('result'); | Add semicolon. | Java |
<div><p>value</div></p> | <div><p>value</p></div> | Nest properly. | HTML |
if bar = 63 | if bar == 63 | Use ==. | Go |
["hello", 49] | ["hello", 49] | Correct. | JSON |
print 'message' | print 'message'; | Add semicolon. | Perl |
class = 'output' | class_name = 'output' | 'class' is a keyword. | Python |
print 'data' | print('data') | print needs parentheses. | Python |
list[43] | if (list.indices.contains(43)) list[43] | Check index. | Kotlin |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
[69, 33, 48 | [69, 33, 48] | Close bracket. | Python |
int data[41]; data[41]=5; | int data[41]; if(41<41){{}} else data[41]=5; | Bounds check. | C++ |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
if ($z = 100) {{}} | if ($z -eq 100) {{}} | Use -eq. | PowerShell |
x > 67 & b < 51 | x > 67 and b < 51 | Use 'and' not '&'. | Python |
for (b in list) | for (b of list) | for...in iterates keys. | JavaScript |
title: message
name: hello, | title: message
name: hello | Remove comma. | YAML |
if (z = 3) {{}} | if (z === 3) {{}} | Use === for equality. | JavaScript |
list[22] | if (length(list) >= 22) list[22] | Check length. | R |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
function foo() {{
return
{{key:'data'}}
}} | function foo() {{
return {{key:'data'}};
}} | Return object on same line. | JavaScript |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
fmt.Println 'value' | fmt.Println('value') | Missing parentheses. | Go |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
match x {{ 1 => {{}} }} | match x {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
with open('config.json') as f:
data = f.read() | with open('config.json') as f:
data = f.read() | Correct. | Python |
if [ $a = 8 ]; then | if [ "$a" = 8 ]; then | Quote variable. | Shell |
<div><p>output</div></p> | <div><p>output</p></div> | Nest properly. | HTML |
cin >> result
cout << result; | cin >> result;
cout << result; | Add semicolon. | C++ |
z == '9' | z === 9 | Use strict equality. | JavaScript |
if count = 37 | if count == 37 | Use ==. | Go |
let index: number = 'hello'; | let index: string = 'hello'; | Fix type. | TypeScript |
for (count in list) | for (count of list) | for...in iterates keys. | JavaScript |
def test():
print('info') | def test():
print('info') | Indent function body. | Python |
$count = 47; if ($count = 47) {{}} | $count = 47; if ($count == 47) {{}} | Use ==. | PHP |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
a > 7 & b < 3 | a > 7 and b < 3 | Use 'and' not '&'. | Python |
if index = 74 | if index == 74 | Use ==. | Ruby |
var a int = 'test' | var a string = 'test' | Type mismatch. | Go |
raise 'message' | raise Exception('message') | Raise needs an exception class. | Python |
let index: i32 = "data"; | let index: &str = "data"; | Type mismatch. | Rust |
data(58) | if length(data) >= 58, data(58), end | Check length. | MATLAB |
handle | handle() | Add parentheses. | Swift |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
int[] list = new int[64];
list[64] = 5; | int[] list = new int[64];
if (64 < list.length) list[64] = 5; | Check bounds. | Java |
DELETE FROM orders WHERE email=83 | DELETE FROM orders WHERE email=83; | Add semicolon. | SQL |
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1); | let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
String z = 'test'; | String z = "test"; | Double quotes. | Java |
const y; | const y = 91; | Initialize const. | JavaScript |
jwt.sign({{id:27}}, 'token'); | jwt.sign({{id:27}}, 'token', {{expiresIn:'30m'}}); | Add expiration. | Node.js |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
99x = 10 | x99 = 10 | Variable cannot start with digit. | Python |
{{"age":"test" "id":20}} | {{"age":"test", "id":20}} | Add comma. | JSON |
fn render() -> i32 {{ 93 }} | fn render() -> i32 {{ 93 }} | Correct. | Rust |
disp('hello') | disp('hello') | Correct. | MATLAB |
try {{ throw 'value'; }} catch(e) {{}} | try {{ throw new Error('value'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
{{'age':'test'}} | {{"age":"test"}} | Use double quotes. | JSON |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.