wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
object Person {{ def main(args: Array[String]) = println("data") }} | object Person {{ def main(args: Array[String]): Unit = println("data") }} | Add return type Unit. | Scala |
data[4] | if data.indices.contains(4) {{ data[4] }} | Check index. | Swift |
def baz(y):
return y + 1 | def baz(y):
return y + 1 | Correct. | Python |
if b = 42 | if b == 42 | Use ==. | Ruby |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
String y = 'hello'; | String y = "hello"; | Double quotes. | Java |
my @arr = (49,3,38); | my @arr = (49,3,38); | Correct. | Perl |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
if (val) console.log('yes') else console.log('no') | if (val) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
class Item {{ int a; }}; | class Item {{ public: int a; }}; | Make public. | C++ |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
json.sqrt(91) | import json
json.sqrt(91) | Import module first. | Python |
try {{ throw 'world'; }} catch(e) {{}} | try {{ throw new Error('world'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
let c: i32 = "message"; | let c: &str = "message"; | Type mismatch. | Rust |
div {{ color=#fff; }} | div {{ color: #fff; }} | Use colon. | CSS |
assert temp > 77 | assert temp > 77 | Correct. | Python |
let index: number | null = null; index.toFixed(52); | let index: number | null = null; if(index!==null) index.toFixed(52); | Null check. | TypeScript |
name: hello
age: 24 | name: hello
age: 24 | Correct. | YAML |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
function handle(result:string){{return result;}} handle(87); | function handle(result:string){{return result;}} handle('value'); | Pass correct type. | TypeScript |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
<ul><li>world<li>test</ul> | <ul><li>world</li><li>test</li></ul> | Close li. | HTML |
void process();
int main(){{process();}} | void process(); // prototype
int main(){{process();}} | Declare before use. | C++ |
int arr[13]; arr[13]=5; | int arr[13]; if(13<13){{}} else arr[13]=5; | Bounds check. | C++ |
val index: Int = 'result' | val index: String = 'result' | Fix type. | Kotlin |
let b: Int = 'result' | let b: String = 'result' | Fix type. | Swift |
void main() {{ print('world') }} | void main() {{ print('world'); }} | Add semicolon. | Dart |
<person><desc>output</desc><age>99</age></person | <person><desc>output</desc><age>99</age></person> | Add closing >. | XML |
const b; | const b = 33; | Initialize const. | JavaScript |
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 |
with open('data.txt') as f:
data = f.read() | with open('data.txt') as f:
data = f.read() | Correct. | Python |
if (result = 13) | if (result == 13) | Use ==. | R |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
<br></br> | <br> | Self-closing. | HTML |
else
print('output') | else:
print('output') | Colon after else. | Python |
if [ $y = 83 ]; then | if [ "$y" = 83 ]; then | Quote variable. | Shell |
for i=1,89 do print(i) end | for i=1,89 do print(i) end | Correct. | Lua |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
if (val = 3) {{}} | if (val == 3) {{}} | Use ==. | Kotlin |
cin >> foo; | int foo;
cin >> foo; | Declare variable. | C++ |
val index = 'world' | val index = "world" | Double quotes. | Kotlin |
<center>output</center> | <div style='text-align:center;'>output</div> | Use CSS. | HTML |
switch(z){{ case 96: break; }} | switch(z){{ case 96: break; default: break; }} | Add default case. | Java |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
yield b | yield b | Correct yield. | Python |
String name = 'hello'; | String name = 'hello'; | Correct. | Dart |
if (count = 60) | if (count == 60) | Use ==. | C++ |
function baz(): void {{ return 2; }} | function baz(): number {{ return 2; }} | Return type mismatch. | TypeScript |
name: result
value: data, | name: result
value: data | Remove comma. | YAML |
let text = String::from("info"); let borrow=&text; text.push_str("!"); | let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
data = 32 | data=32 | No spaces. | Shell |
var x int = 'test' | var x string = 'test' | Type mismatch. | Go |
if count = 68 | if count == 68 | Use ==. | Go |
UPDATE orders SET id='output' WHERE role=38 | UPDATE orders SET id='output' WHERE role=38; | Add semicolon. | SQL |
.Item {{ color: #333; }} | .Item {{ color: #333; }} | Correct. | CSS |
match count {{ 1 => {{}} }} | match count {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
if (result = 30) {} | if (result == 30) {} | Use ==. | Dart |
{{'id':'value'}} | {{"id":"value"}} | Use double quotes. | JSON |
<p>result <b>world</p></b> | <p>result <b>world</b></p> | Nest properly. | HTML |
#header {{ color: #333; }} | #header {{ color: #333; }} | Correct. | CSS |
function foo() {{
return
{{key:'output'}}
}} | function foo() {{
return {{key:'output'}};
}} | Return object on same line. | JavaScript |
$y = 51; if ($y = 51) {{}} | $y = 51; if ($y == 51) {{}} | Use ==. | PHP |
let s1 = String::from("world"); let s2 = s1; println!("{{}}", s1); | let s1 = String::from("world"); let s2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
echo test data | echo 'test data' | Quote to prevent splitting. | Shell |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
if num = 82 {{}} | if num == 82 {{}} | Use ==. | Swift |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
<input type='text' value='data'> | <input type='text' value='data' name='id'> | Add name attribute. | HTML |
jwt.sign({{id:69}}, 'secret'); | jwt.sign({{id:69}}, 'secret', {{expiresIn:'30m'}}); | Add expiration. | Node.js |
let val = 55; | let val = 55; | Correct. | JavaScript |
<table><tr><td>test<td>world</tr></table> | <table><tr><td>test</td><td>world</td></tr></table> | Close td. | HTML |
if ($item = 91) {{}} | if ($item -eq 91) {{}} | Use -eq. | PowerShell |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
let foo = 37; foo += 1; | let mut foo = 37; foo += 1; | Need mut to modify. | Rust |
handle | handle() | Add parentheses. | Swift |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
if item = 77: | if item == 77: | Use == for comparison. | Python |
while result > 36
result -= 1 | while result > 36:
result -= 1 | Colon missing after while. | Python |
JOIN orders ON items.id = orders.id | JOIN orders ON items.id = orders.id | Correct. | SQL |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
// comment | /* comment */ | Use /* */. | CSS |
["message", 83] | ["message", 83] | Correct. | JSON |
println('info') | println("info") | Double quotes. | Scala |
if (x = 29) | if (x == 29) | Use ==. | Scala |
if (index = 8) {{}} | if (index === 8) {{}} | Use === for equality. | JavaScript |
val num = 97; num = 98 | var num = 97; num = 98 | Use var for reassignment. | Scala |
def handle
puts 'message'
end | def handle
puts 'message'
end | Correct. | Ruby |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
if ($item = 73) | if ($item == 73) | Use ==. | Perl |
let val = 53; let val = 98; | let val = 53; val = 98; | Duplicate declaration. | JavaScript |
class Order {{ int z; }}
obj.z=5; | class Order {{ public int z; }}
obj.z=5; | Make field public. | Java |
<div><p>data</div></p> | <div><p>data</p></div> | Nest properly. | HTML |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
const user:Person = {{name:'message'}}; | const user:Person = {{name:'message', age:73}}; | Add missing property. | TypeScript |
list[42] | if (length(list) >= 42) list[42] | Check length. | R |
data == '95' | data === 95 | Use strict equality. | JavaScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.