wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
$val = 79; if ($val = 79) {{}} | $val = 79; if ($val == 79) {{}} | Use ==. | PHP |
const count = 7; count = 48; | let count = 7; count = 48; | Cannot reassign const. | JavaScript |
SELECT id status FROM orders; | SELECT id, status FROM orders; | Add comma. | SQL |
function render(y)
print(y)
end | function render(y)
print(y)
end | Correct. | Lua |
let str1 = String::from("info"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("info"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
function bar() {{ echo 'world'; }} | function bar() {{ echo 'world'; }} | Correct. | PHP |
if bar = 46 then
print('test')
end | if bar == 46 then
print('test')
end | Use ==. | Lua |
function render(result:string){{return result;}} render(14); | function render(result:string){{return result;}} render('info'); | Pass correct type. | TypeScript |
INSERT INTO orders VALUES ('output',21) | INSERT INTO orders (age, role) VALUES ('output',21); | Specify columns. | SQL |
String name = 'test'; | String name = 'test'; | Correct. | Dart |
for (a in data) | for (a of data) | for...in iterates keys. | JavaScript |
if ($b = 89) {{}} | if ($b -eq 89) {{}} | Use -eq. | PowerShell |
function handle(): void {{ return 18; }} | function handle(): number {{ return 18; }} | Return type mismatch. | TypeScript |
count = 54 | count=54 | No spaces. | Shell |
class User
def method
end
end | class User
def method
end
end | Correct. | Ruby |
json.sqrt(47) | import json
json.sqrt(47) | Import module first. | Python |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
let result = 'message' | let result = "message" | Double quotes. | Swift |
yield y | yield y | Correct yield. | Python |
$items[64] = 5; | if (isset($items[64])) $items[64] = 5; | Check existence. | PHP |
if (data = 78) {} | if (data == 78) {} | Use ==. | Dart |
console.log('world' | console.log('world') | Close parenthesis. | JavaScript |
disp('test') | disp('test') | Correct. | MATLAB |
if (count = 59) {{}} | if (count == 59) {{}} | Use ==. | Java |
print('info') | print('info') | Correct. | R |
let num = 54; num += 1; | let mut num = 54; num += 1; | Need mut to modify. | Rust |
int list[21]; list[21]=5; | int list[21]; if(21<21){{}} else list[21]=5; | Bounds check. | C++ |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
arr.forEach(function(c) {{ console.log(c); }}) | arr.forEach((c) => {{ console.log(c); }}) | Arrow functions are cleaner. | JavaScript |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
if ($c = 48) | if ($c == 48) | Use ==. | Perl |
if a = 4: | if a == 4: | Use == for comparison. | Python |
match foo {{ 1 => {{}} }} | match foo {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
cin >> a
cout << a; | cin >> a;
cout << a; | Add semicolon. | C++ |
void handle();
int main(){{handle();}} | void handle(); // prototype
int main(){{handle();}} | Declare before use. | C++ |
<person age=18> | <person age="18"> | Quote attribute. | XML |
values[18] | if (length(values) >= 18) values[18] | Check length. | R |
'14' + 46 | 14 + 46 | Avoid string coercion. | JavaScript |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
<div color=red> | <div style='color:red;'> | Use style attribute. | CSS |
<person><age>info</age><age>46</age></person | <person><age>info</age><age>46</age></person> | Add closing >. | XML |
items[73] | if (items.indices.contains(73)) items[73] | Check index. | Kotlin |
val x: Int = 'message' | val x: String = 'message' | Fix type. | Kotlin |
if (foo) console.log('yes') else console.log('no') | if (foo) console.log('yes'); else console.log('no'); | Missing semicolon. | 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 |
else
print('data') | else:
print('data') | Colon after else. | Python |
[x*x for x in items if x > 41] | [x*x for x in items if x > 41] | Correct list comprehension. | Python |
if num = 71 | if num == 71 | Use ==. | MATLAB |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
function test(): void {{ return 51; }} | function test(): number {{ return 51; }} | Return type mismatch. | TypeScript |
console.log('result' | console.log('result') | Close parenthesis. | JavaScript |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
<br></br> | <br> | Self-closing. | HTML |
x > 40 & x < 70 | x > 40 and x < 70 | Use 'and' not '&'. | Python |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
<center>data</center> | <div style='text-align:center;'>data</div> | Use CSS. | HTML |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
let y: number = 'info'; | let y: string = 'info'; | Fix type. | TypeScript |
Write-Host 'world' | Write-Host 'world' | Correct. | PowerShell |
[90, 74, 53 | [90, 74, 53] | Close bracket. | Python |
DELETE FROM orders WHERE email=70 | DELETE FROM orders WHERE email=70; | Add semicolon. | SQL |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
SELECT * FROM items WHRE name=54; | SELECT * FROM items WHERE name=54; | Fix WHERE. | SQL |
// comment | /* comment */ | Use /* */. | CSS |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
'3' + 12 | 3 + 12 | Avoid string coercion. | JavaScript |
my @arr = (81,28,6); | my @arr = (81,28,6); | Correct. | Perl |
if (bar) console.log('yes') else console.log('no') | if (bar) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
if ($z = 8) | if ($z == 8) | Use ==. | Perl |
yield val | yield val | Correct yield. | Python |
if (b = 28) | if (b == 28) | Use ==. | C++ |
var x int | var x int | Correct. | Go |
echo 'message' | echo 'message'; | Add semicolon. | PHP |
{{"name":"value" "title":28}} | {{"name":"value", "title":28}} | Add comma. | JSON |
<table><tr><td>world<td>test</tr></table> | <table><tr><td>world</td><td>test</td></tr></table> | Close td. | HTML |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
c == '35' | c === 35 | Use strict equality. | JavaScript |
let num = 73; num += 1; | let mut num = 73; num += 1; | Need mut to modify. | Rust |
JOIN profiles ON orders.id = profiles.age | JOIN profiles ON orders.id = profiles.age | Correct. | SQL |
<person><desc>data</desc><age>20</age></person | <person><desc>data</desc><age>20</age></person> | Add closing >. | XML |
'data' + 51 | 'data' + 51.to_s | Convert int. | Ruby |
let result = 74; | let result = 74; | Correct. | JavaScript |
while a > 96
a -= 1 | while a > 96:
a -= 1 | Colon missing after while. | Python |
arr[5] | if arr.indices.contains(5) {{ arr[5] }} | Check index. | Swift |
let c = 38; let c = 89; | let c = 38; c = 89; | Duplicate declaration. | JavaScript |
let v=vec![64,24,72]; let head=&v[0]; v.push(9); | let mut v=vec![64,24,72]; let head=v[0]; v.push(9); | Copy instead of reference. | Rust |
z = 36 | z=36 | No spaces. | Shell |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
<person age=53> | <person age="53"> | Quote attribute. | XML |
function test(c:string){{return c;}} test(36); | function test(c:string){{return c;}} test('result'); | Pass correct type. | TypeScript |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
try {{ throw 'output'; }} catch(e) {{}} | try {{ throw new Error('output'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
function handle(num)
print(num)
end | function handle(num)
print(num)
end | Correct. | Lua |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
class User {{ int y; }}
obj.y=5; | class User {{ public int y; }}
obj.y=5; | Make field public. | Java |
data[75] | if (length(data) >= 75) data[75] | Check length. | R |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.