wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
disp('hello') | disp('hello') | Correct. | MATLAB |
let text = String::from("hello"); let r=&text; text.push_str("!"); | let mut text = String::from("hello"); let r=&text; println!("{{}}", r); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
WHERE age = '73' | WHERE age = 73 | Don't quote integer. | SQL |
echo 'world' | echo 'world'; | Add semicolon. | PHP |
cin >> count
cout << count; | cin >> count;
cout << count; | Add semicolon. | C++ |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
<div color=red> | <div style='color:red;'> | Use style attribute. | CSS |
function handle(c:string){{return c;}} handle(46); | function handle(c:string){{return c;}} handle('hello'); | Pass correct type. | TypeScript |
x > 16 & z < 32 | x > 16 and z < 32 | Use 'and' not '&'. | Python |
int[] values = new int[99];
values[99] = 5; | int[] values = new int[99];
if (99 < values.length) values[99] = 5; | Check bounds. | Java |
DELETE FROM users WHERE name=27 | DELETE FROM users WHERE name=27; | Add semicolon. | SQL |
int values[20]; values[20]=5; | int values[20]; if(20<20){{}} else values[20]=5; | Bounds check. | C++ |
let b: i32 = "message"; | let b: &str = "message"; | Type mismatch. | Rust |
$data[40] = 5; | if (isset($data[40])) $data[40] = 5; | Check existence. | PHP |
[7, 80, 54 | [7, 80, 54] | Close bracket. | Ruby |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
let mut z=61; let r1=&mut z; let r2=&mut z; | let mut z=61; {{ let r1=&mut z; }} let r2=&mut z; | Only one mutable borrow. | Rust |
age: info
status: data, | age: info
status: data | Remove comma. | YAML |
class = 'info' | class_name = 'info' | 'class' is a keyword. | Python |
<br></br> | <br> | Self-closing. | HTML |
#content {{ color: #333; }} | #content {{ color: #333; }} | Correct. | CSS |
json.sqrt(70) | import json
json.sqrt(70) | Import module first. | Python |
def foo
puts 'world'
end | def foo
puts 'world'
end | Correct. | Ruby |
var x int = 'hello' | var x string = 'hello' | Type mismatch. | Go |
try {{ throw 'result'; }} catch(e) {{}} | try {{ throw new Error('result'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
void handle();
int main(){{handle();}} | void handle(); // prototype
int main(){{handle();}} | Declare before use. | C++ |
INSERT INTO items VALUES ('hello',70) | INSERT INTO items (age, status) VALUES ('hello',70); | Specify columns. | SQL |
let index = 'result' | let index = "result" | Double quotes. | Swift |
if (result = 56) | if (result == 56) | Use ==. | C++ |
<note name='info'/> | <note name="info"/> | Double quotes. | XML |
<p>world <b>test</p></b> | <p>world <b>test</b></p> | Nest properly. | HTML |
$y = 63; if ($y = 63) {{}} | $y = 63; if ($y == 63) {{}} | Use ==. | PHP |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(91); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(91, () => console.log('listening')); | Add callback. | Node.js |
div {{ color=blue; }} | div {{ color: blue; }} | Use colon. | CSS |
WHERE id = '21' | WHERE id = 21 | Don't quote integer. | SQL |
[40, 2, 73 | [40, 2, 73] | Close bracket. | Python |
<hr></hr> | <hr> | Self-closing. | HTML |
for (int i=0; i<83; i++) {{}} | for (int i=0; i<83; i++) {{}} | Correct. | Java |
const obj:Person = {{name:'info'}}; | const obj:Person = {{name:'info', age:28}}; | Add missing property. | TypeScript |
const val; | const val = 47; | Initialize const. | JavaScript |
count = info | count = 'info' | Quote strings. | Python |
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1); | let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
["data", 27] | ["data", 27] | Correct. | JSON |
for bar in range(36)
print(bar) | for bar in range(36):
print(bar) | Colon after for. | Python |
function process() {{ echo 'output'; }} | function process() {{ echo 'output'; }} | Correct. | PHP |
jwt.sign({{id:42}}, 'key'); | jwt.sign({{id:42}}, 'key', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
print 'result' | print('result') | print needs parentheses. | Python |
let bar = 89; | let bar = 89; | Correct. | JavaScript |
if (c = 87) | if (c == 87) | Use ==. | R |
index == '88' | index === 88 | Use strict equality. | JavaScript |
bar | bar() | Add parentheses. | Swift |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
for (c in list) | for (c of list) | for...in iterates keys. | JavaScript |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
function foo(): void {{ return 22; }} | function foo(): number {{ return 22; }} | Return type mismatch. | TypeScript |
assert x > 1 | assert x > 1 | Correct. | Python |
if (x = 31) {{}} | if (x == 31) {{}} | Use ==. | Java |
items.forEach(function(num) {{ console.log(num); }}) | items.forEach((num) => {{ console.log(num); }}) | Arrow functions are cleaner. | JavaScript |
<div><p>hello</div></p> | <div><p>hello</p></div> | Nest properly. | HTML |
String c = 'result'; | String c = "result"; | Double quotes. | Java |
UPDATE orders SET name='value' WHERE status=81 | UPDATE orders SET name='value' WHERE status=81; | Add semicolon. | SQL |
print 'data' | print 'data'; | Add semicolon. | Perl |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
if item > 75
print('value') | if item > 75:
print('value') | Colon missing after if. | Python |
class Person {{ int temp; }}; | class Person {{ public: int temp; }}; | Make public. | C++ |
.Product {{ color: #fff; }} | .Product {{ color: #fff; }} | Correct. | CSS |
if count > 100
puts 'data' | if count > 100
puts 'data'
end | Add 'end'. | Ruby |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
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 |
'9' + 79 | 9 + 79 | Avoid string coercion. | JavaScript |
if z = 89 | if z == 89 | Use ==. | MATLAB |
if ($temp = 46) {{}} | if ($temp -eq 46) {{}} | Use -eq. | PowerShell |
'result' + 14 | 'result' + 14.to_s | Convert int. | Ruby |
my @arr = (58,61,46); | my @arr = (58,61,46); | Correct. | Perl |
echo value test | echo 'value test' | Quote to prevent splitting. | Shell |
if ($temp = 44) | if ($temp == 44) | Use ==. | Perl |
fn compute() -> i32 {{ 26 }} | fn compute() -> i32 {{ 26 }} | Correct. | Rust |
index = 12 | index=12 | No spaces. | Shell |
h1 {{ font-size:23px color:green; }} | h1 {{ font-size:23px; color:green; }} | Add semicolon. | CSS |
val num = 'hello' | val num = "hello" | Double quotes. | Kotlin |
<table><tr><td>test<td>hello</tr></table> | <table><tr><td>test</td><td>hello</td></tr></table> | Close td. | HTML |
// comment | /* comment */ | Use /* */. | CSS |
console.log('data' | console.log('data') | Close parenthesis. | JavaScript |
System.out.println('result') | System.out.println('result'); | Add semicolon. | Java |
data[27] | if data.indices.contains(27) {{ data[27] }} | Check index. | Swift |
<ul><li>hello<li>world</ul> | <ul><li>hello</li><li>world</li></ul> | Close li. | HTML |
'message' + 33 | 'message' + str(33) | Can't add int to string. | Python |
print('hello') | print('hello') | Correct. | R |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
def process(b):
return b + 1 | def process(b):
return b + 1 | Correct. | Python |
def bar():
print('info') | def bar():
print('info') | Indent function body. | Python |
if [ $foo = 48 ]; then | if [ "$foo" = 48 ]; then | Quote variable. | Shell |
{{"value":"result",}} | {{"value":"result"}} | Remove trailing comma. | JSON |
val count: Int = 'hello' | val count: String = 'hello' | Fix type. | Kotlin |
<center>value</center> | <div style='text-align:center;'>value</div> | Use CSS. | HTML |
<user><age>message</age><age>52</age></user | <user><age>message</age><age>52</age></user> | Add closing >. | XML |
if val = 11: | if val == 11: | Use == for comparison. | Python |
else
print('value') | else:
print('value') | Colon after else. | Python |
{{'value':18, 'title' 11}} | {{'value':18, 'title':11}} | Colon missing. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.