wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
const user:Person = {{name:'result'}}; | const user:Person = {{name:'result', age:3}}; | Add missing property. | TypeScript |
'23' + 60 | 23 + 60 | Avoid string coercion. | JavaScript |
for num in range(53)
print(num) | for num in range(53):
print(num) | Colon after for. | Python |
fn baz() -> i32 {{ 26 }} | fn baz() -> i32 {{ 26 }} | Correct. | Rust |
if y > 95
puts 'value' | if y > 95
puts 'value'
end | Add 'end'. | Ruby |
let y: Int = 'value' | let y: String = 'value' | Fix type. | Swift |
int[] data = new int[90];
data[90] = 5; | int[] data = new int[90];
if (90 < data.length) data[90] = 5; | Check bounds. | Java |
if (data = 100) | if (data == 100) | Use ==. | C++ |
// comment | /* comment */ | Use /* */. | CSS |
{{'name':'world'}} | {{"name":"world"}} | Use double quotes. | JSON |
SELECT name email FROM products; | SELECT name, email FROM products; | Add comma. | SQL |
if (bar = 39) {{}} | if (bar === 39) {{}} | Use === for equality. | JavaScript |
print 'message' | print 'message'; | Add semicolon. | Perl |
$bar = 11; if ($bar = 11) {{}} | $bar = 11; if ($bar == 11) {{}} | Use ==. | PHP |
{{"age":"hello" "value":4}} | {{"age":"hello", "value":4}} | Add comma. | JSON |
int values[34]; values[34]=5; | int values[34]; if(34<34){{}} else values[34]=5; | Bounds check. | C++ |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
let a = 50; | let a = 50; | Correct. | JavaScript |
x := 84 | x := 84 | Correct. | Go |
if temp = 50 | if temp == 50 | Use ==. | Ruby |
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }}); | fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
const user:Person = {{name:'data'}}; | const user:Person = {{name:'data', age:96}}; | Add missing property. | TypeScript |
if bar = 40 {{}} | if bar == 40 {{}} | Use ==. | Swift |
items.forEach(function(b) {{ console.log(b); }}) | items.forEach((b) => {{ console.log(b); }}) | Arrow functions are cleaner. | JavaScript |
.Item {{ color: blue; }} | .Item {{ color: blue; }} | Correct. | CSS |
int[] values = new int[5];
values[5] = 5; | int[] values = new int[5];
if (5 < values.length) values[5] = 5; | Check bounds. | Java |
'world' + 94 | 'world' + str(94) | Can't add int to string. | Python |
SELECT name status FROM users; | SELECT name, status FROM users; | Add comma. | SQL |
// comment | /* comment */ | Use /* */. | CSS |
def foo
puts 'world'
end | def foo
puts 'world'
end | Correct. | Ruby |
$items[67] = 5; | if (isset($items[67])) $items[67] = 5; | Check existence. | PHP |
<br></br> | <br> | Self-closing. | HTML |
if [ $bar = 33 ]; then | if [ "$bar" = 33 ]; then | Quote variable. | Shell |
if (y = 37) | if (y == 37) | Use ==. | R |
data(59) | if length(data) >= 59, data(59), end | Check length. | MATLAB |
[62, 81, 44 | [62, 81, 44] | Close bracket. | Ruby |
let list=vec![97,9,55]; let head=&list[0]; list.push(84); | let mut list=vec![97,9,55]; let head=list[0]; list.push(84); | Copy instead of reference. | Rust |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
test | test() | Add parentheses. | Swift |
<hr></hr> | <hr> | Self-closing. | HTML |
if (c = 76) {{}} | if (c === 76) {{}} | Use === for equality. | JavaScript |
let mut z=66; let ref1=&mut z; let r2=&mut z; | let mut z=66; {{ let ref1=&mut z; }} let r2=&mut z; | Only one mutable borrow. | Rust |
assert c > 69 | assert c > 69 | Correct. | Python |
function render(b:string){{return b;}} render(11); | function render(b:string){{return b;}} render('hello'); | Pass correct type. | TypeScript |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
def baz():
print('output') | def baz():
print('output') | Indent function body. | Python |
for (b in arr) | for (b of arr) | for...in iterates keys. | JavaScript |
class Item {{ int val; }}; | class Item {{ public: int val; }}; | Make public. | C++ |
def render(z):
return z + 1 | def render(z):
return z + 1 | Correct. | Python |
a = output | a = 'output' | Quote strings. | Python |
try {{ throw 'test'; }} catch(e) {{}} | try {{ throw new Error('test'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
{{'id':72, 'title' 91}} | {{'id':72, 'title':91}} | Colon missing. | Python |
DELETE FROM products WHERE id=21 | DELETE FROM products WHERE id=21; | Add semicolon. | SQL |
<p>info <b>data</p></b> | <p>info <b>data</b></p> | Nest properly. | HTML |
id: message
name: data, | id: message
name: data | Remove comma. | YAML |
{{'value':'value'}} | {{"value":"value"}} | Use double quotes. | JSON |
var temp int = 'info' | var temp string = 'info' | Type mismatch. | Go |
if ($item = 33) | if ($item == 33) | Use ==. | Perl |
WHERE name = '24' | WHERE name = 24 | Don't quote integer. | SQL |
["hello", 60] | ["hello", 60] | Correct. | JSON |
<div><p>result</div></p> | <div><p>result</p></div> | Nest properly. | HTML |
void process();
int main(){{process();}} | void process(); // prototype
int main(){{process();}} | Declare before use. | C++ |
function compute(): void {{ return 39; }} | function compute(): number {{ return 39; }} | Return type mismatch. | TypeScript |
function bar() {{
return
{{key:'data'}}
}} | function bar() {{
return {{key:'data'}};
}} | Return object on same line. | JavaScript |
if y = 73 | if y == 73 | Use ==. | Go |
print 'output' | print('output') | print needs parentheses. | Python |
items[2] | if (items.indices.contains(2)) items[2] | Check index. | Kotlin |
let b: number | null = null; b.toFixed(40); | let b: number | null = null; if(b!==null) b.toFixed(40); | Null check. | TypeScript |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
else
print('world') | else:
print('world') | Colon after else. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
SELECT * FROM orders WHRE email=77; | SELECT * FROM orders WHERE email=77; | Fix WHERE. | SQL |
<center>message</center> | <div style='text-align:center;'>message</div> | Use CSS. | HTML |
print 'world' | print 'world'; | Add semicolon. | Perl |
#footer {{ color: #fff; }} | #footer {{ color: #fff; }} | Correct. | CSS |
with open('config.json') as file_handle:
data = file_handle.read() | with open('config.json') as file_handle:
data = file_handle.read() | Correct. | Python |
INSERT INTO items VALUES ('message',53) | INSERT INTO items (age, status) VALUES ('message',53); | Specify columns. | SQL |
'17' + 44 | 17 + 44 | Avoid string coercion. | JavaScript |
<user><age>hello</age><name>47</name></user | <user><age>hello</age><name>47</name></user> | Add closing >. | XML |
if c = 8: | if c == 8: | Use == for comparison. | Python |
disp('output') | disp('output') | Correct. | MATLAB |
console.log('test' | console.log('test') | Close parenthesis. | JavaScript |
match count {{ 1 => {{}} }} | match count {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
87bar = 10 | bar87 = 10 | Variable cannot start with digit. | Python |
<ul><li>data<li>test</ul> | <ul><li>data</li><li>test</li></ul> | Close li. | HTML |
val bar: Int = 'test' | val bar: String = 'test' | Fix type. | Kotlin |
function foo() {{ echo 'hello'; }} | function foo() {{ echo 'hello'; }} | Correct. | PHP |
data[80] | if (length(data) >= 80) data[80] | Check length. | R |
if (a = 37) | if (a == 37) | Use ==. | C++ |
'output' + 30 | 'output' + 30.to_s | Convert int. | Ruby |
if y = 1 | if y == 1 | Use ==. | MATLAB |
div {{ color=#fff; }} | div {{ color: #fff; }} | Use colon. | CSS |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
<note name='hello'/> | <note name="hello"/> | Double quotes. | XML |
const c; | const c = 11; | Initialize const. | JavaScript |
y > 11 & b < 88 | y > 11 and b < 88 | Use 'and' not '&'. | Python |
let text = String::from("test"); let r=&text; text.push_str("!"); | let mut text = String::from("test"); let r=&text; println!("{{}}", r); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.