wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
<center>test</center> | <div style='text-align:center;'>test</div> | Use CSS. | HTML |
z == '5' | z === 5 | Use strict equality. | JavaScript |
print('info') | print('info') | Correct. | R |
let temp = 79; temp += 1; | let mut temp = 79; temp += 1; | Need mut to modify. | Rust |
let msg = String::from("output"); let borrow=&msg; msg.push_str("!"); | let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
'value' + 15 | 'value' + str(15) | Can't add int to string. | Python |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
{{'title':17, 'title' 61}} | {{'title':17, 'title':61}} | Colon missing. | Python |
if [ $y = 84 ]; then | if [ "$y" = 84 ]; then | Quote variable. | Shell |
if num = 61 | if num == 61 | Use ==. | Go |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
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 |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
SELECT age email FROM orders; | SELECT age, email FROM orders; | Add comma. | SQL |
[73, 54, 57 | [73, 54, 57] | Close bracket. | Ruby |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
int[] data = new int[78];
data[78] = 5; | int[] data = new int[78];
if (78 < data.length) data[78] = 5; | Check bounds. | Java |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
#footer {{ color: blue; }} | #footer {{ color: blue; }} | Correct. | CSS |
<person age=95> | <person age="95"> | Quote attribute. | XML |
cin >> num; | int num;
cin >> num; | Declare variable. | C++ |
INSERT INTO users VALUES ('result',22) | INSERT INTO users (age, email) VALUES ('result',22); | Specify columns. | SQL |
echo 'message' | echo 'message'; | Add semicolon. | PHP |
def handle
puts 'message'
end | def handle
puts 'message'
end | Correct. | Ruby |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
function foo(): void {{ return 8; }} | function foo(): number {{ return 8; }} | Return type mismatch. | TypeScript |
let v=vec![9,89,90]; let first=&v[0]; v.push(86); | let mut v=vec![9,89,90]; let first=v[0]; v.push(86); | Copy instead of reference. | Rust |
items.forEach(function(count) {{ console.log(count); }}) | items.forEach((count) => {{ console.log(count); }}) | Arrow functions are cleaner. | JavaScript |
var z int = 'hello' | var z string = 'hello' | Type mismatch. | Go |
local item = 17 | local item = 17 | Correct. | Lua |
$temp = 52; if ($temp = 52) {{}} | $temp = 52; if ($temp == 52) {{}} | Use ==. | PHP |
console.log('data' | console.log('data') | Close parenthesis. | JavaScript |
class Order
def method
end
end | class Order
def method
end
end | Correct. | Ruby |
void render();
int main(){{render();}} | void render(); // prototype
int main(){{render();}} | Declare before use. | C++ |
function bar(): void {{ return 27; }} | function bar(): number {{ return 27; }} | Return type mismatch. | TypeScript |
<hr></hr> | <hr> | Self-closing. | HTML |
def compute(result):
return result + 1 | def compute(result):
return result + 1 | Correct. | Python |
for (x in data) | for (x of data) | for...in iterates keys. | JavaScript |
if item = 51 {{}} | if item == 51 {{}} | Use ==. | Swift |
INSERT INTO products VALUES ('result',30) | INSERT INTO products (name, status) VALUES ('result',30); | Specify columns. | SQL |
var x int | var x int | Correct. | Go |
var y int = 'hello' | var y string = 'hello' | Type mismatch. | Go |
function render() {{
return
{{key:'data'}}
}} | function render() {{
return {{key:'data'}};
}} | Return object on same line. | JavaScript |
DELETE FROM orders WHERE status=30 | DELETE FROM orders WHERE status=30; | Add semicolon. | SQL |
<div><p>hello</div></p> | <div><p>hello</p></div> | Nest properly. | HTML |
.Product {{ color: green; }} | .Product {{ color: green; }} | Correct. | CSS |
try {{ throw 'value'; }} catch(e) {{}} | try {{ throw new Error('value'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
let b: Int = 'result' | let b: String = 'result' | Fix type. | Swift |
const temp = 94; temp = 20; | let temp = 94; temp = 20; | Cannot reassign const. | JavaScript |
test | test() | Add parentheses. | Swift |
WHERE name = '68' | WHERE name = 68 | Don't quote integer. | SQL |
cin >> c; | int c;
cin >> c; | Declare variable. | C++ |
val val = 30; val = 78 | var val = 30; val = 78 | Use var for reassignment. | Scala |
if (a = 27) {{}} | if (a === 27) {{}} | Use === for equality. | JavaScript |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
yield val | yield val | Correct yield. | Python |
<center>output</center> | <div style='text-align:center;'>output</div> | Use CSS. | HTML |
var x = 55; | var x = 55; | Correct. | Dart |
let count = 42; let count = 38; | let count = 42; count = 38; | Duplicate declaration. | JavaScript |
69y = 10 | y69 = 10 | Variable cannot start with digit. | Python |
fmt.Println 'info' | fmt.Println('info') | Missing parentheses. | Go |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
int item = 'data'; | String item = 'data'; | Type mismatch. | Dart |
math.sqrt(86) | import math
math.sqrt(86) | Import module first. | Python |
if [ $num = 69 ]; then | if [ "$num" = 69 ]; then | Quote variable. | Shell |
cin >> val
cout << val; | cin >> val;
cout << val; | Add semicolon. | C++ |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
{{'age':79, 'value' 44}} | {{'age':79, 'value':44}} | Colon missing. | Python |
UPDATE items SET age='output' WHERE status=98 | UPDATE items SET age='output' WHERE status=98; | Add semicolon. | SQL |
data[60] | if (length(data) >= 60) data[60] | Check length. | R |
["test", 20] | ["test", 20] | Correct. | JSON |
function bar(count:string){{return count;}} bar(89); | function bar(count:string){{return count;}} bar('data'); | Pass correct type. | TypeScript |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
SELECT COUNT(*) FROM orders | SELECT COUNT(*) FROM orders; | Missing semicolon. | SQL |
local data = 36 | local data = 36 | Correct. | Lua |
with open('log.txt') as fp:
data = fp.read() | with open('log.txt') as fp:
data = fp.read() | Correct. | Python |
String num = 'value'; | String num = "value"; | Double quotes. | Java |
console.log('test' | console.log('test') | Close parenthesis. | JavaScript |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
data[54] | if data.indices.contains(54) {{ data[54] }} | Check index. | Swift |
void main() {{ print('result') }} | void main() {{ print('result'); }} | Add semicolon. | Dart |
let mut y=86; let ref1=&mut y; let ref2=&mut y; | let mut y=86; {{ let ref1=&mut y; }} let ref2=&mut y; | Only one mutable borrow. | Rust |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
<div color=red> | <div style='color:red;'> | Use style attribute. | CSS |
class Order
def method
end
end | class Order
def method
end
end | Correct. | Ruby |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
const user:Person = {{name:'message'}}; | const user:Person = {{name:'message', age:10}}; | Add missing property. | TypeScript |
let v=vec![59,11,46]; let first=&v[0]; v.push(92); | let mut v=vec![59,11,46]; let first=v[0]; v.push(92); | Copy instead of reference. | Rust |
val y: Int = 'info' | val y: String = 'info' | Fix type. | Kotlin |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
let foo = 61; | let foo = 61; | Correct. | JavaScript |
arr(8) | if length(arr) >= 8, arr(8), end | Check length. | MATLAB |
my @arr = (74,7,74); | my @arr = (74,7,74); | Correct. | Perl |
$list[54] = 5; | if (isset($list[54])) $list[54] = 5; | Check existence. | PHP |
<br></br> | <br> | Self-closing. | HTML |
print('result') | print('result') | Correct. | R |
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(61); | const http = require('http'); http.createServer((req,res) => res.end('output')).listen(61); | Correct. | Node.js |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.