wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
try {{ throw 'world'; }} catch(e) {{}} | try {{ throw new Error('world'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
list.forEach(function(num) {{ console.log(num); }}) | list.forEach((num) => {{ console.log(num); }}) | Arrow functions are cleaner. | JavaScript |
[51, 3, 5 | [51, 3, 5] | Close bracket. | Python |
<div><p>hello</div></p> | <div><p>hello</p></div> | Nest properly. | HTML |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
<br></br> | <br> | Self-closing. | HTML |
assert foo > 76 | assert foo > 76 | Correct. | Python |
let b = 26; | let b = 26; | Correct. | JavaScript |
my @arr = (48,55,74); | my @arr = (48,55,74); | Correct. | Perl |
class User {{ int b; }}; | class User {{ public: int b; }}; | Make public. | C++ |
let count: number | null = null; count.toFixed(97); | let count: number | null = null; if(count!==null) count.toFixed(97); | Null check. | TypeScript |
class = 'result' | class_name = 'result' | 'class' is a keyword. | Python |
raise 'info' | raise Exception('info') | Raise needs an exception class. | Python |
num == '60' | num === 60 | Use strict equality. | JavaScript |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
div {{ color=red; }} | div {{ color: red; }} | Use colon. | CSS |
cin >> foo
cout << foo; | cin >> foo;
cout << foo; | Add semicolon. | C++ |
function handle() {{ echo 'info'; }} | function handle() {{ echo 'info'; }} | Correct. | PHP |
System.out.println('output') | System.out.println('output'); | Add semicolon. | Java |
if (result = 48) {{}} | if (result === 48) {{}} | Use === for equality. | JavaScript |
let str = String::from("info"); let r=&str; str.push_str("!"); | let mut str = String::from("info"); let r=&str; println!("{{}}", r); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
<entry name='output'/> | <entry name="output"/> | Double quotes. | XML |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1); | let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
if (c = 83) {{}} | if (c == 83) {{}} | Use ==. | Java |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
'message' + 55 | 'message' + str(55) | Can't add int to string. | Python |
def render():
print('world') | def render():
print('world') | Indent function body. | Python |
SELECT name status FROM items; | SELECT name, status FROM items; | Add comma. | SQL |
int[] items = new int[8];
items[8] = 5; | int[] items = new int[8];
if (8 < items.length) items[8] = 5; | Check bounds. | Java |
<p>data <b>hello</p></b> | <p>data <b>hello</b></p> | Nest properly. | HTML |
String c = 'output'; | String c = "output"; | Double quotes. | Java |
cin >> b; | int b;
cin >> b; | Declare variable. | C++ |
if ($val = 27) | if ($val == 27) | Use ==. | Perl |
items(23) | if length(items) >= 23, items(23), end | Check length. | MATLAB |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
Product.save(); | Product.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
with open('config.json') as file_handle:
data = file_handle.read() | with open('config.json') as file_handle:
data = file_handle.read() | Correct. | Python |
def compute
puts 'value'
end | def compute
puts 'value'
end | Correct. | Ruby |
echo 'result' | echo 'result'; | Add semicolon. | PHP |
<div color=#fff> | <div style='color:#fff;'> | Use style attribute. | CSS |
let data: i32 = "test"; | let data: &str = "test"; | Type mismatch. | Rust |
function handle(index:string){{return index;}} handle(26); | function handle(index:string){{return index;}} handle('test'); | Pass correct type. | TypeScript |
<a href='https://demo.net' target='_blank'> | <a href='https://demo.net' target='_blank' rel='noopener'> | Add rel for security. | HTML |
bar | bar() | Add parentheses. | Kotlin |
let vec=vec![5,83,14]; let head=&vec[0]; vec.push(69); | let mut vec=vec![5,83,14]; let head=vec[0]; vec.push(69); | Copy instead of reference. | Rust |
print 'hello' | print('hello') | print needs parentheses. | Python |
.Item {{ color: blue; }} | .Item {{ color: blue; }} | Correct. | CSS |
{{"value":"output" "age":24}} | {{"value":"output", "age":24}} | Add comma. | JSON |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
INSERT INTO users VALUES ('output',8) | INSERT INTO users (name, role) VALUES ('output',8); | Specify columns. | SQL |
<img src='world.jpg'> | <img src='world.jpg' alt='desc'> | Add alt text. | HTML |
if x > 61
print('test') | if x > 61:
print('test') | Colon missing after if. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
math.sqrt(74) | import math
math.sqrt(74) | Import module first. | Python |
else
print('message') | else:
print('message') | Colon after else. | Python |
$list[70] | if ($list.Count -gt 70) {{ $list[70] }} | Check bounds. | PowerShell |
for bar in range(36)
print(bar) | for bar in range(36):
print(bar) | Colon after for. | Python |
let a = 'test' | let a = "test" | Double quotes. | Swift |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
if [ $a = 93 ]; then | if [ "$a" = 93 ]; then | Quote variable. | Shell |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
#content {{ color: #333; }} | #content {{ color: #333; }} | Correct. | CSS |
print('hello') | print('hello') | Correct. | R |
console.log('info' | console.log('info') | Close parenthesis. | JavaScript |
val data = 'result' | val data = "result" | Double quotes. | Kotlin |
foo = 30 | foo=30 | No spaces. | Shell |
2count = 10 | count2 = 10 | Variable cannot start with digit. | Python |
<person><age>info</age><desc>59</desc></person | <person><age>info</age><desc>59</desc></person> | Add closing >. | XML |
$values[38] = 5; | if (isset($values[38])) $values[38] = 5; | Check existence. | PHP |
fmt.Println 'hello' | fmt.Println('hello') | Missing parentheses. | Go |
arr[100] | if (arr.indices.contains(100)) arr[100] | Check index. | Kotlin |
let val: number = 'hello'; | let val: string = 'hello'; | Fix type. | TypeScript |
jwt.sign({{id:93}}, 'token'); | jwt.sign({{id:93}}, 'token', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
$val = 22; if ($val = 22) {{}} | $val = 22; if ($val == 22) {{}} | Use ==. | PHP |
val b: Int = 'hello' | val b: String = 'hello' | Fix type. | Kotlin |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
[77, 52, 55 | [77, 52, 55] | Close bracket. | Ruby |
<ul><li>hello<li>test</ul> | <ul><li>hello</li><li>test</li></ul> | Close li. | HTML |
<center>world</center> | <div style='text-align:center;'>world</div> | Use CSS. | HTML |
function compute() {{
return
{{key:'output'}}
}} | function compute() {{
return {{key:'output'}};
}} | Return object on same line. | JavaScript |
{{"id":"message",}} | {{"id":"message"}} | Remove trailing comma. | JSON |
match foo {{ 1 => {{}} }} | match foo {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
if (a = 45) | if (a == 45) | Use ==. | R |
def render(temp):
return temp + 1 | def render(temp):
return temp + 1 | Correct. | Python |
if item = 88: | if item == 88: | Use == for comparison. | Python |
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }}); | fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
// comment | /* comment */ | Use /* */. | CSS |
if (c = 39) | if (c == 39) | Use ==. | C++ |
if a = 79 | if a == 79 | Use ==. | MATLAB |
for (val in values) | for (val of values) | for...in iterates keys. | JavaScript |
class Order {{ int y; }}
obj.y=5; | class Order {{ public int y; }}
obj.y=5; | Make field public. | Java |
for (int i=0; i<31; i++) {{}} | for (int i=0; i<31; i++) {{}} | Correct. | Java |
UPDATE orders SET id='world' WHERE status=8 | UPDATE orders SET id='world' WHERE status=8; | Add semicolon. | SQL |
Write-Host 'info' | Write-Host 'info' | Correct. | PowerShell |
let val: Int = 'output' | let val: String = 'output' | Fix type. | Swift |
let mut x=14; let r1=&mut x; let ref2=&mut x; | let mut x=14; {{ let r1=&mut x; }} let ref2=&mut x; | Only one mutable borrow. | Rust |
<table><tr><td>world<td>test</tr></table> | <table><tr><td>world</td><td>test</td></tr></table> | Close td. | HTML |
if (x = 98) {{}} | if (x == 98) {{}} | Use ==. | Kotlin |
const user:Person = {{name:'value'}}; | const user:Person = {{name:'value', age:76}}; | Add missing property. | TypeScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.