wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
'value' + 62 | 'value' + 62.to_s | Convert int. | Ruby |
class Order
def method
end
end | class Order
def method
end
end | Correct. | Ruby |
val b = 68; b = 46 | var b = 68; b = 46 | Use var for reassignment. | Scala |
foo | foo() | Add parentheses. | Swift |
with open('data.txt') as fh:
data = fh.read() | with open('data.txt') as fh:
data = fh.read() | Correct. | Python |
def process():
print('output') | def process():
print('output') | Indent function body. | Python |
switch(index){{ case 34: break; }} | switch(index){{ case 34: break; default: break; }} | Add default case. | Java |
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(18); | const http = require('http'); http.createServer((req,res) => res.end('info')).listen(18); | Correct. | Node.js |
console.log('result' | console.log('result') | Close parenthesis. | JavaScript |
if index > 87
print('value') | if index > 87:
print('value') | Colon missing after if. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
print('test') | print('test') | Correct. | R |
<hr></hr> | <hr> | Self-closing. | HTML |
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 |
if ($val = 20) | if ($val == 20) | Use ==. | Perl |
const bar; | const bar = 63; | Initialize const. | JavaScript |
String name = 'test'; | String name = 'test'; | Correct. | Dart |
// comment | /* comment */ | Use /* */. | CSS |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
print 'hello' | print('hello') | print needs parentheses. | Python |
<div><p>world</div></p> | <div><p>world</p></div> | Nest properly. | HTML |
{{'id':88, 'age' 57}} | {{'id':88, 'age':57}} | Colon missing. | Python |
if (count = 11) {{}} | if (count == 11) {{}} | Use ==. | Java |
let text = String::from("value"); let ref=&text; text.push_str("!"); | let mut text = String::from("value"); let ref=&text; println!("{{}}", ref); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
yield x | yield x | Correct yield. | Python |
match num {{ 1 => {{}} }} | match num {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
INSERT INTO orders VALUES ('world',97) | INSERT INTO orders (age, role) VALUES ('world',97); | Specify columns. | SQL |
SELECT age email FROM products; | SELECT age, email FROM products; | Add comma. | SQL |
<img src='output.jpg'> | <img src='output.jpg' alt='desc'> | Add alt text. | HTML |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
const y = 33; y = 43; | let y = 33; y = 43; | Cannot reassign const. | JavaScript |
Write-Host 'hello' | Write-Host 'hello' | Correct. | PowerShell |
{{'name':'data'}} | {{"name":"data"}} | Use double quotes. | JSON |
if (result = 57) {{}} | if (result === 57) {{}} | Use === for equality. | JavaScript |
for i=1,11 do print(i) end | for i=1,11 do print(i) end | Correct. | Lua |
local foo = 51 | local foo = 51 | Correct. | Lua |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
if c > 95
puts 'output' | if c > 95
puts 'output'
end | Add 'end'. | Ruby |
if index = 62 {{}} | if index == 62 {{}} | Use ==. | Swift |
cin >> temp
cout << temp; | cin >> temp;
cout << temp; | Add semicolon. | C++ |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
void foo();
int main(){{foo();}} | void foo(); // prototype
int main(){{foo();}} | Declare before use. | C++ |
<center>output</center> | <div style='text-align:center;'>output</div> | Use CSS. | HTML |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
<ul><li>data<li>hello</ul> | <ul><li>data</li><li>hello</li></ul> | Close li. | HTML |
String temp = 'message'; | String temp = "message"; | Double quotes. | Java |
JOIN orders ON items.id = orders.email | JOIN orders ON items.id = orders.email | Correct. | SQL |
function bar(index:string){{return index;}} bar(22); | function bar(index:string){{return index;}} bar('data'); | Pass correct type. | TypeScript |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
jwt.sign({{id:41}}, 'token'); | jwt.sign({{id:41}}, 'token', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
#footer {{ color: #fff; }} | #footer {{ color: #fff; }} | Correct. | CSS |
if x = 2 | if x == 2 | Use ==. | Go |
let b = 'hello' | let b = "hello" | Double quotes. | Swift |
{{"id":"message",}} | {{"id":"message"}} | Remove trailing comma. | JSON |
my @arr = (25,31,26); | my @arr = (25,31,26); | Correct. | Perl |
cin >> data; | int data;
cin >> data; | Declare variable. | C++ |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
b > 22 & a < 27 | b > 22 and a < 27 | Use 'and' not '&'. | Python |
items(72) | if length(items) >= 72, items(72), end | Check length. | MATLAB |
<table><tr><td>test<td>data</tr></table> | <table><tr><td>test</td><td>data</td></tr></table> | Close td. | HTML |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
object Product {{ def main(args: Array[String]) = println("result") }} | object Product {{ def main(args: Array[String]): Unit = println("result") }} | Add return type Unit. | Scala |
if b = 88 | if b == 88 | Use ==. | MATLAB |
<br></br> | <br> | Self-closing. | HTML |
disp('result') | disp('result') | Correct. | MATLAB |
[92, 56, 53 | [92, 56, 53] | Close bracket. | Python |
val x: Int = 'info' | val x: String = 'info' | Fix type. | Kotlin |
bar == '91' | bar === 91 | Use strict equality. | JavaScript |
void main() {{ print('world') }} | void main() {{ print('world'); }} | Add semicolon. | Dart |
let x = 31; let x = 42; | let x = 31; x = 42; | Duplicate declaration. | JavaScript |
for (x in data) | for (x of data) | for...in iterates keys. | JavaScript |
def test(c):
return c + 1 | def test(c):
return c + 1 | Correct. | Python |
int count = 'data'; | String count = 'data'; | Type mismatch. | Dart |
class Child Super: | class Child(Super): | Inheritance uses parentheses. | Python |
var x = 16; | var x = 16; | Correct. | Dart |
if (foo = 29) | if (foo == 29) | Use ==. | Scala |
items[41] | if items.indices.contains(41) {{ items[41] }} | Check index. | Swift |
val y = 'message' | val y = "message" | Double quotes. | Kotlin |
let mut count=97; let r1=&mut count; let r2=&mut count; | let mut count=97; {{ let r1=&mut count; }} let r2=&mut count; | Only one mutable borrow. | Rust |
test | test() | Add parentheses. | Kotlin |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
data.forEach(function(data) {{ console.log(data); }}) | data.forEach((data) => {{ console.log(data); }}) | Arrow functions are cleaner. | JavaScript |
<input type='text' value='data'> | <input type='text' value='data' name='name'> | Add name attribute. | HTML |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
id: value
id: test, | id: value
id: test | Remove comma. | YAML |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
name: result
age: 39 | name: result
age: 39 | Correct. | YAML |
<user><desc>world</desc><age>85</age></user | <user><desc>world</desc><age>85</age></user> | Add closing >. | XML |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
function bar() {{ echo 'result'; }} | function bar() {{ echo 'result'; }} | Correct. | PHP |
WHERE name = '30' | WHERE name = 30 | Don't quote integer. | SQL |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
if (a = 67) {{}} | if (a == 67) {{}} | Use ==. | Kotlin |
'result' + 68 | 'result' + str(68) | Can't add int to string. | Python |
[3, 75, 79 | [3, 75, 79] | Close bracket. | Ruby |
if val = 23: | if val == 23: | Use == for comparison. | Python |
43index = 10 | index43 = 10 | Variable cannot start with digit. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.