wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
[18, 11, 4 | [18, 11, 4] | Close bracket. | Ruby |
while index > 88
index -= 1 | while index > 88:
index -= 1 | Colon missing after while. | Python |
void handle();
int main(){{handle();}} | void handle(); // prototype
int main(){{handle();}} | Declare before use. | C++ |
if (a = 34) | if (a == 34) | Use ==. | C++ |
const index; | const index = 37; | Initialize const. | JavaScript |
if (bar = 80) {{}} | if (bar === 80) {{}} | Use === for equality. | JavaScript |
String num = 'world'; | String num = "world"; | Double quotes. | Java |
for (val in arr) | for (val of arr) | for...in iterates keys. | JavaScript |
items[84] | if (items.indices.contains(84)) items[84] | Check index. | Kotlin |
echo output hello | echo 'output hello' | Quote to prevent splitting. | Shell |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
let bar = 57; bar += 1; | let mut bar = 57; bar += 1; | Need mut to modify. | Rust |
<div color=#333> | <div style='color:#333;'> | Use style attribute. | CSS |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
a > 53 & b < 37 | a > 53 and b < 37 | Use 'and' not '&'. | Python |
process | process() | Add parentheses. | Swift |
56bar = 10 | bar56 = 10 | Variable cannot start with digit. | Python |
function foo(temp:string){{return temp;}} foo(53); | function foo(temp:string){{return temp;}} foo('world'); | Pass correct type. | TypeScript |
WHERE id = '63' | WHERE id = 63 | Don't quote integer. | SQL |
print 'world' | print('world') | print needs parentheses. | Python |
if [ $data = 61 ]; then | if [ "$data" = 61 ]; then | Quote variable. | Shell |
class Item {{ int count; }}
obj.count=5; | class Item {{ public int count; }}
obj.count=5; | Make field public. | Java |
#content {{ color: blue; }} | #content {{ color: blue; }} | Correct. | CSS |
num == '31' | num === 31 | Use strict equality. | JavaScript |
if foo > 17
puts 'hello' | if foo > 17
puts 'hello'
end | Add 'end'. | Ruby |
if c = 51: | if c == 51: | Use == for comparison. | Python |
<center>data</center> | <div style='text-align:center;'>data</div> | Use CSS. | HTML |
assert data > 48 | assert data > 48 | Correct. | Python |
match foo {{ 1 => {{}} }} | match foo {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
temp = 67 | temp=67 | No spaces. | Shell |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
'22' + 2 | 22 + 2 | Avoid string coercion. | JavaScript |
if index = 16 | if index == 16 | Use ==. | MATLAB |
class Product {{ int temp; }}; | class Product {{ public: int temp; }}; | Make public. | C++ |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
switch(x){{ case 80: break; }} | switch(x){{ case 80: break; default: break; }} | Add default case. | Java |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
<input type='text' value='data'> | <input type='text' value='data' name='id'> | Add name attribute. | HTML |
let val = 14; | let val = 14; | Correct. | JavaScript |
Write-Host 'info' | Write-Host 'info' | Correct. | PowerShell |
.Order {{ color: #fff; }} | .Order {{ color: #fff; }} | Correct. | CSS |
let index: Int = 'message' | let index: String = 'message' | Fix type. | Swift |
$values[34] = 5; | if (isset($values[34])) $values[34] = 5; | Check existence. | PHP |
console.log('hello' | console.log('hello') | Close parenthesis. | JavaScript |
x = message | x = 'message' | Quote strings. | Python |
try {{ throw 'data'; }} catch(e) {{}} | try {{ throw new Error('data'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
DELETE FROM orders WHERE id=46 | DELETE FROM orders WHERE id=46; | Add semicolon. | SQL |
<user name='message'/> | <user name="message"/> | Double quotes. | XML |
jwt.sign({{id:67}}, 'token'); | jwt.sign({{id:67}}, 'token', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
let vec=vec![40,81,49]; let head=&vec[0]; vec.push(3); | let mut vec=vec![40,81,49]; let head=vec[0]; vec.push(3); | Copy instead of reference. | Rust |
function render(c)
print(c)
end | function render(c)
print(c)
end | Correct. | Lua |
if (item = 90) {{}} | if (item === 90) {{}} | Use === for equality. | JavaScript |
INSERT INTO users VALUES ('hello',80) | INSERT INTO users (age, status) VALUES ('hello',80); | Specify columns. | SQL |
x := 62 | x := 62 | Correct. | Go |
$x = 49; if ($x = 49) {{}} | $x = 49; if ($x == 49) {{}} | Use ==. | PHP |
z == '18' | z === 18 | Use strict equality. | JavaScript |
def handle
puts 'output'
end | def handle
puts 'output'
end | Correct. | Ruby |
val z = 39; z = 77 | var z = 39; z = 77 | Use var for reassignment. | Scala |
.Item {{ color: blue; }} | .Item {{ color: blue; }} | Correct. | CSS |
bar | bar() | Add parentheses. | Swift |
let foo: Int = 'value' | let foo: String = 'value' | Fix type. | Swift |
const temp = 13; temp = 63; | let temp = 13; temp = 63; | Cannot reassign const. | JavaScript |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
if foo > 40
print('hello') | if foo > 40:
print('hello') | Colon missing after if. | Python |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
data[17] | if (length(data) >= 17) data[17] | Check length. | R |
val val = 'output' | val val = "output" | Double quotes. | Kotlin |
'value' + 54 | 'value' + str(54) | Can't add int to string. | Python |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
print 'message' | print 'message'; | Add semicolon. | Perl |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
int values[57]; values[57]=5; | int values[57]; if(57<57){{}} else values[57]=5; | Bounds check. | C++ |
x = info | x = 'info' | Quote strings. | Python |
class Product {{ int a; }}; | class Product {{ public: int a; }}; | Make public. | C++ |
def handle(y):
return y + 1 | def handle(y):
return y + 1 | Correct. | Python |
let z = 79; let z = 90; | let z = 79; z = 90; | Duplicate declaration. | JavaScript |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
UPDATE items SET status='hello' WHERE role=64 | UPDATE items SET status='hello' WHERE role=64; | Add semicolon. | SQL |
status: result
value: data, | status: result
value: data | Remove comma. | YAML |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(51); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(51, () => console.log('listening')); | Add callback. | Node.js |
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 |
if count = 70 then
print('result')
end | if count == 70 then
print('result')
end | Use ==. | Lua |
#content {{ color: #fff; }} | #content {{ color: #fff; }} | Correct. | CSS |
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 |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
if data = 78: | if data == 78: | Use == for comparison. | Python |
["data", 64] | ["data", 64] | Correct. | JSON |
print 'message' | print('message') | print needs parentheses. | Python |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
let x: number = 'test'; | let x: string = 'test'; | Fix type. | TypeScript |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
if foo = 71 | if foo == 71 | Use ==. | MATLAB |
let num = 54; num += 1; | let mut num = 54; num += 1; | Need mut to modify. | Rust |
var x = 31; | var x = 31; | Correct. | Dart |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.