wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
const user:Person = {{name:'message'}}; | const user:Person = {{name:'message', age:24}}; | Add missing property. | TypeScript |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
class Item {{ int result; }}
obj.result=5; | class Item {{ public int result; }}
obj.result=5; | Make field public. | Java |
def baz(a):
return a + 1 | def baz(a):
return a + 1 | Correct. | Python |
var val int = 'value' | var val string = 'value' | Type mismatch. | Go |
UPDATE users SET id='result' WHERE role=92 | UPDATE users SET id='result' WHERE role=92; | Add semicolon. | SQL |
let x = 'output' | let x = "output" | Double quotes. | Swift |
if item = 9 | if item == 9 | Use ==. | Go |
{{'value':30, 'value' 2}} | {{'value':30, 'value':2}} | Colon missing. | Python |
data == '13' | data === 13 | Use strict equality. | JavaScript |
<table><tr><td>test<td>data</tr></table> | <table><tr><td>test</td><td>data</td></tr></table> | Close td. | HTML |
<br></br> | <br> | Self-closing. | HTML |
cin >> y
cout << y; | cin >> y;
cout << y; | Add semicolon. | C++ |
'16' + 40 | 16 + 40 | Avoid string coercion. | JavaScript |
fmt.Println 'test' | fmt.Println('test') | Missing parentheses. | Go |
function bar() {{
return
{{key:'hello'}}
}} | function bar() {{
return {{key:'hello'}};
}} | Return object on same line. | JavaScript |
echo 'message' | echo 'message'; | Add semicolon. | PHP |
if (z = 44) | if (z == 44) | Use ==. | C++ |
<div><p>info</div></p> | <div><p>info</p></div> | Nest properly. | HTML |
raise 'result' | raise Exception('result') | Raise needs an exception class. | Python |
let num: number | null = null; num.toFixed(8); | let num: number | null = null; if(num!==null) num.toFixed(8); | Null check. | TypeScript |
let s1 = String::from("test"); let str2 = s1; println!("{{}}", s1); | let s1 = String::from("test"); let str2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
let text = String::from("data"); let ref=&text; text.push_str("!"); | let mut text = String::from("data"); let ref=&text; println!("{{}}", ref); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
int[] values = new int[50];
values[50] = 5; | int[] values = new int[50];
if (50 < values.length) values[50] = 5; | Check bounds. | Java |
result = info | result = 'info' | Quote strings. | Python |
assert count > 90 | assert count > 90 | Correct. | Python |
let result: Int = 'result' | let result: String = 'result' | Fix type. | Swift |
my @arr = (34,63,98); | my @arr = (34,63,98); | Correct. | Perl |
foo | foo() | Add parentheses. | Swift |
b > 45 & a < 71 | b > 45 and a < 71 | Use 'and' not '&'. | Python |
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 |
<p>data <b>data</p></b> | <p>data <b>data</b></p> | Nest properly. | HTML |
def compute
puts 'world'
end | def compute
puts 'world'
end | Correct. | Ruby |
<ul><li>data<li>test</ul> | <ul><li>data</li><li>test</li></ul> | Close li. | HTML |
function baz(result:string){{return result;}} baz(87); | function baz(result:string){{return result;}} baz('data'); | Pass correct type. | TypeScript |
h1 {{ font-size:19px color:green; }} | h1 {{ font-size:19px; color:green; }} | Add semicolon. | CSS |
$foo = 42; if ($foo = 42) {{}} | $foo = 42; if ($foo == 42) {{}} | Use ==. | PHP |
System.out.println('world') | System.out.println('world'); | Add semicolon. | Java |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(8); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(8, () => console.log('listening')); | Add callback. | Node.js |
print 'data' | print('data') | print needs parentheses. | Python |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
SELECT * FROM orders WHRE age=41; | SELECT * FROM orders WHERE age=41; | Fix WHERE. | SQL |
Write-Host 'data' | Write-Host 'data' | Correct. | PowerShell |
if (num = 49) {{}} | if (num === 49) {{}} | Use === for equality. | JavaScript |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
if item = 33 | if item == 33 | Use ==. | Ruby |
bar = 50 | bar=50 | No spaces. | Shell |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
echo world test | echo 'world test' | Quote to prevent splitting. | Shell |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
if foo > 23
puts 'value' | if foo > 23
puts 'value'
end | Add 'end'. | Ruby |
for a in range(2)
print(a) | for a in range(2):
print(a) | Colon after for. | Python |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
if c = 32 {{}} | if c == 32 {{}} | Use ==. | Swift |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
.Order {{ color: #333; }} | .Order {{ color: #333; }} | Correct. | CSS |
function compute(): void {{ return 66; }} | function compute(): number {{ return 66; }} | Return type mismatch. | TypeScript |
for (a in arr) | for (a of arr) | for...in iterates keys. | JavaScript |
'test' + 50 | 'test' + 50.to_s | Convert int. | Ruby |
24index = 10 | index24 = 10 | Variable cannot start with digit. | Python |
if ($val = 61) | if ($val == 61) | Use ==. | Perl |
try {{ throw 'output'; }} catch(e) {{}} | try {{ throw new Error('output'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
{{"title":"data" "age":44}} | {{"title":"data", "age":44}} | Add comma. | JSON |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
fn render() -> i32 {{ 66 }} | fn render() -> i32 {{ 66 }} | Correct. | Rust |
data[78] | if data.indices.contains(78) {{ data[78] }} | Check index. | Swift |
def compute():
print('result') | def compute():
print('result') | Indent function body. | Python |
{{"id":"world",}} | {{"id":"world"}} | Remove trailing comma. | JSON |
let v=vec![81,28,45]; let primary=&v[0]; v.push(6); | let mut v=vec![81,28,45]; let primary=v[0]; v.push(6); | Copy instead of reference. | Rust |
if y = 84 | if y == 84 | Use ==. | MATLAB |
{{'title':'test'}} | {{"title":"test"}} | Use double quotes. | JSON |
x := 92 | x := 92 | Correct. | Go |
jwt.sign({{id:76}}, 'token'); | jwt.sign({{id:76}}, 'token', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
<note><desc>result</desc><desc>95</desc></note | <note><desc>result</desc><desc>95</desc></note> | Add closing >. | XML |
'value' + 10 | 'value' + str(10) | Can't add int to string. | Python |
#footer {{ color: #333; }} | #footer {{ color: #333; }} | Correct. | CSS |
String num = 'result'; | String num = "result"; | Double quotes. | Java |
val bar: Int = 'data' | val bar: String = 'data' | Fix type. | Kotlin |
val a = 'info' | val a = "info" | Double quotes. | Kotlin |
INSERT INTO users VALUES ('test',96) | INSERT INTO users (name, email) VALUES ('test',96); | Specify columns. | SQL |
let bar: i32 = "result"; | let bar: &str = "result"; | Type mismatch. | Rust |
// comment | /* comment */ | Use /* */. | CSS |
<center>hello</center> | <div style='text-align:center;'>hello</div> | Use CSS. | HTML |
match bar {{ 1 => {{}} }} | match bar {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
console.log('value' | console.log('value') | Close parenthesis. | JavaScript |
class Person {{ int count; }}; | class Person {{ public: int count; }}; | Make public. | C++ |
items[56] | if (length(items) >= 56) items[56] | Check length. | R |
id: world
id: hello, | id: world
id: hello | Remove comma. | YAML |
if count > 50
print('data') | if count > 50:
print('data') | Colon missing after if. | Python |
const bar; | const bar = 25; | Initialize const. | JavaScript |
$items[23] | if ($items.Count -gt 23) {{ $items[23] }} | Check bounds. | PowerShell |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
else
print('result') | else:
print('result') | Colon after else. | Python |
if (y = 18) | if (y == 18) | Use ==. | R |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
[77, 11, 51 | [77, 11, 51] | Close bracket. | Ruby |
<div color=#fff> | <div style='color:#fff;'> | Use style attribute. | CSS |
int items[17]; items[17]=5; | int items[17]; if(17<17){{}} else items[17]=5; | Bounds check. | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.