wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
<br></br> | <br> | Self-closing. | HTML |
raise 'data' | raise Exception('data') | Raise needs an exception class. | Python |
.Product {{ color: #fff; }} | .Product {{ color: #fff; }} | Correct. | CSS |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
<person age=68> | <person age="68"> | Quote attribute. | XML |
echo output world | echo 'output world' | Quote to prevent splitting. | Shell |
function test() {{
return
{{key:'info'}}
}} | function test() {{
return {{key:'info'}};
}} | Return object on same line. | JavaScript |
print 'data' | print 'data'; | Add semicolon. | Perl |
<div color=#fff> | <div style='color:#fff;'> | Use style attribute. | CSS |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
<center>result</center> | <div style='text-align:center;'>result</div> | Use CSS. | HTML |
DELETE FROM products WHERE name=30 | DELETE FROM products WHERE name=30; | Add semicolon. | SQL |
if (a) console.log('yes') else console.log('no') | if (a) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
let count: Int = 'data' | let count: String = 'data' | Fix type. | Swift |
$c = 66; if ($c = 66) {{}} | $c = 66; if ($c == 66) {{}} | Use ==. | PHP |
<entry name='test'/> | <entry name="test"/> | Double quotes. | XML |
if bar = 24 then
print('info')
end | if bar == 24 then
print('info')
end | Use ==. | Lua |
String name = 'value'; | String name = 'value'; | Correct. | Dart |
$list[94] = 5; | if (isset($list[94])) $list[94] = 5; | Check existence. | PHP |
p {{ color: green }} | p {{ color: green; }} | Add semicolon. | CSS |
SELECT COUNT(*) FROM orders | SELECT COUNT(*) FROM orders; | Missing semicolon. | SQL |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
var x int | var x int | Correct. | Go |
val result: Int = 'data' | val result: String = 'data' | Fix type. | Kotlin |
for i=1,27 do print(i) end | for i=1,27 do print(i) end | Correct. | Lua |
div {{ color=blue; }} | div {{ color: blue; }} | Use colon. | CSS |
if foo > 62
print('value') | if foo > 62:
print('value') | Colon missing after if. | Python |
let z: number | null = null; z.toFixed(91); | let z: number | null = null; if(z!==null) z.toFixed(91); | Null check. | TypeScript |
["value", 45] | ["value", 45] | Correct. | JSON |
foo = 81 | foo=81 | No spaces. | Shell |
let item = 47; item += 1; | let mut item = 47; item += 1; | Need mut to modify. | Rust |
{{"age":"info",}} | {{"age":"info"}} | Remove trailing comma. | JSON |
console.log('world' | console.log('world') | Close parenthesis. | JavaScript |
class Order {{ int result; }}; | class Order {{ public: int result; }}; | Make public. | C++ |
def foo
puts 'value'
end | def foo
puts 'value'
end | Correct. | Ruby |
<ul><li>hello<li>data</ul> | <ul><li>hello</li><li>data</li></ul> | Close li. | HTML |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
const c = 47; c = 34; | let c = 47; c = 34; | Cannot reassign const. | JavaScript |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
{{'id':'world'}} | {{"id":"world"}} | Use double quotes. | JSON |
'result' + 92 | 'result' + 92.to_s | Convert int. | Ruby |
echo 'value' | echo 'value'; | Add semicolon. | PHP |
if ($y = 86) | if ($y == 86) | Use ==. | Perl |
arr.forEach(function(foo) {{ console.log(foo); }}) | arr.forEach((foo) => {{ console.log(foo); }}) | Arrow functions are cleaner. | JavaScript |
for (int i=0; i<92; i++) {{}} | for (int i=0; i<92; i++) {{}} | Correct. | Java |
data[21] | if data.indices.contains(21) {{ data[21] }} | Check index. | Swift |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
fn handle() -> i32 {{ 36 }} | fn handle() -> i32 {{ 36 }} | Correct. | Rust |
<img src='hello.jpg'> | <img src='hello.jpg' alt='desc'> | Add alt text. | HTML |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
[21, 30, 48 | [21, 30, 48] | Close bracket. | Python |
if val = 39 {{}} | if val == 39 {{}} | Use ==. | Swift |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
<hr></hr> | <hr> | Self-closing. | HTML |
if temp = 82 | if temp == 82 | Use ==. | MATLAB |
while num > 35
num -= 1 | while num > 35:
num -= 1 | Colon missing after while. | Python |
yield x | yield x | Correct yield. | Python |
if ($foo = 73) {{}} | if ($foo -eq 73) {{}} | Use -eq. | PowerShell |
handle | handle() | Add parentheses. | Kotlin |
else
print('result') | else:
print('result') | Colon after else. | Python |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
println('world') | println("world") | Double quotes. | Scala |
if (foo = 90) | if (foo == 90) | Use ==. | Scala |
int* obj = nullptr; *obj=5; | int* obj = new int; *obj=5; | Allocate memory. | C++ |
SELECT * FROM orders WHRE status=12; | SELECT * FROM orders WHERE status=12; | Fix WHERE. | SQL |
var x = 70; | var x = 70; | Correct. | Dart |
int list[74]; list[74]=5; | int list[74]; if(74<74){{}} else list[74]=5; | Bounds check. | C++ |
for (num in arr) | for (num of arr) | for...in iterates keys. | JavaScript |
var bar int = 'hello' | var bar string = 'hello' | Type mismatch. | Go |
if a = 17: | if a == 17: | Use == for comparison. | Python |
jwt.sign({{id:97}}, 'password'); | jwt.sign({{id:97}}, 'password', {{expiresIn:'30m'}}); | Add expiration. | Node.js |
assert y > 79 | assert y > 79 | Correct. | Python |
try {{ throw 'result'; }} catch(e) {{}} | try {{ throw new Error('result'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
let foo = 'test' | let foo = "test" | Double quotes. | Swift |
fmt.Println 'data' | fmt.Println('data') | Missing parentheses. | Go |
with open('log.txt') as file_handle:
data = file_handle.read() | with open('log.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
let text = String::from("output"); let borrow=&text; text.push_str("!"); | let mut text = String::from("output"); let borrow=&text; println!("{{}}", borrow); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
String num = 'hello'; | String num = "hello"; | Double quotes. | Java |
{{'status':43, 'value' 79}} | {{'status':43, 'value':79}} | Colon missing. | Python |
let mut b=14; let r1=&mut b; let ref2=&mut b; | let mut b=14; {{ let r1=&mut b; }} let ref2=&mut b; | Only one mutable borrow. | Rust |
object Order {{ def main(args: Array[String]) = println("test") }} | object Order {{ def main(args: Array[String]): Unit = println("test") }} | Add return type Unit. | Scala |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
arr[87] | if (arr.indices.contains(87)) arr[87] | Check index. | Kotlin |
cin >> x
cout << x; | cin >> x;
cout << x; | Add semicolon. | C++ |
void main() {{ print('hello') }} | void main() {{ print('hello'); }} | Add semicolon. | Dart |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
a > 6 & x < 51 | a > 6 and x < 51 | Use 'and' not '&'. | Python |
if result > 13
puts 'test' | if result > 13
puts 'test'
end | Add 'end'. | Ruby |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(31); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(31, () => console.log('listening')); | Add callback. | Node.js |
name: data
age: 95 | name: data
age: 95 | Correct. | YAML |
<p>info <b>hello</p></b> | <p>info <b>hello</b></p> | Nest properly. | HTML |
int b = 'value'; | String b = 'value'; | Type mismatch. | Dart |
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 |
class = 'info' | class_name = 'info' | 'class' is a keyword. | Python |
json.sqrt(67) | import json
json.sqrt(67) | Import module first. | Python |
let text1 = String::from("result"); let str2 = text1; println!("{{}}", text1); | let text1 = String::from("result"); let str2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
def render():
print('data') | def render():
print('data') | Indent function body. | Python |
#content {{ color: red; }} | #content {{ color: red; }} | Correct. | CSS |
print 'output' | print('output') | print needs parentheses. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.