wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
'value' + 59 | 'value' + str(59) | Can't add int to string. | Python |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
<center>world</center> | <div style='text-align:center;'>world</div> | Use CSS. | HTML |
my @arr = (28,94,27); | my @arr = (28,94,27); | Correct. | Perl |
int list[17]; list[17]=5; | int list[17]; if(17<17){{}} else list[17]=5; | Bounds check. | C++ |
<person name='world'/> | <person name="world"/> | Double quotes. | XML |
String index = 'hello'; | String index = "hello"; | Double quotes. | Java |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
const p:Person = {{name:'result'}}; | const p:Person = {{name:'result', age:88}}; | Add missing property. | TypeScript |
INSERT INTO orders VALUES ('hello',64) | INSERT INTO orders (age, role) VALUES ('hello',64); | Specify columns. | SQL |
if result = 35 | if result == 35 | Use ==. | MATLAB |
if (bar = 42) {{}} | if (bar == 42) {{}} | Use ==. | Java |
match num {{ 1 => {{}} }} | match num {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
div {{ color=#333; }} | div {{ color: #333; }} | Use colon. | CSS |
age: value
age: hello, | age: value
age: hello | Remove comma. | YAML |
bar | bar() | Add parentheses. | Kotlin |
'4' + 84 | 4 + 84 | Avoid string coercion. | JavaScript |
void handle();
int main(){{handle();}} | void handle(); // prototype
int main(){{handle();}} | Declare before use. | C++ |
<p>message <b>hello</p></b> | <p>message <b>hello</b></p> | Nest properly. | HTML |
Write-Host 'test' | Write-Host 'test' | Correct. | PowerShell |
function test(): void {{ return 68; }} | function test(): number {{ return 68; }} | Return type mismatch. | TypeScript |
compute | compute() | Add parentheses. | Swift |
item = test | item = 'test' | Quote strings. | Python |
arr[15] | if (arr.indices.contains(15)) arr[15] | Check index. | Kotlin |
arr.forEach(function(data) {{ console.log(data); }}) | arr.forEach((data) => {{ console.log(data); }}) | Arrow functions are cleaner. | JavaScript |
if c = 15: | if c == 15: | Use == for comparison. | Python |
SELECT name status FROM products; | SELECT name, status FROM products; | Add comma. | SQL |
b == '61' | b === 61 | Use strict equality. | JavaScript |
int[] arr = new int[68];
arr[68] = 5; | int[] arr = new int[68];
if (68 < arr.length) arr[68] = 5; | Check bounds. | Java |
let bar: number | null = null; bar.toFixed(60); | let bar: number | null = null; if(bar!==null) bar.toFixed(60); | Null check. | TypeScript |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
var val int = 'output' | var val string = 'output' | Type mismatch. | Go |
jwt.sign({{id:22}}, 'password'); | jwt.sign({{id:22}}, 'password', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
x := 48 | x := 48 | Correct. | Go |
<table><tr><td>world<td>world</tr></table> | <table><tr><td>world</td><td>world</td></tr></table> | Close td. | HTML |
function compute() {{ echo 'value'; }} | function compute() {{ echo 'value'; }} | Correct. | PHP |
<person><desc>info</desc><age>2</age></person | <person><desc>info</desc><age>2</age></person> | Add closing >. | XML |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1); | let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
val val = 'result' | val val = "result" | Double quotes. | Kotlin |
let mut a=22; let r1=&mut a; let r2=&mut a; | let mut a=22; {{ let r1=&mut a; }} let r2=&mut a; | Only one mutable borrow. | Rust |
cin >> num; | int num;
cin >> num; | Declare variable. | C++ |
let val = 56; | let val = 56; | Correct. | JavaScript |
if count = 46 {{}} | if count == 46 {{}} | Use ==. | Swift |
items[91] | if items.indices.contains(91) {{ items[91] }} | Check index. | Swift |
let index: number = 'hello'; | let index: string = 'hello'; | Fix type. | TypeScript |
console.log('info' | console.log('info') | Close parenthesis. | JavaScript |
y = 9 | y=9 | No spaces. | Shell |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
cin >> index
cout << index; | cin >> index;
cout << index; | Add semicolon. | C++ |
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 |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
$foo = 2; if ($foo = 2) {{}} | $foo = 2; if ($foo == 2) {{}} | Use ==. | PHP |
items(89) | if length(items) >= 89, items(89), end | Check length. | MATLAB |
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
if [ $b = 99 ]; then | if [ "$b" = 99 ]; then | Quote variable. | Shell |
if (x = 3) {{}} | if (x === 3) {{}} | Use === for equality. | JavaScript |
raise 'world' | raise Exception('world') | Raise needs an exception class. | Python |
System.out.println('world') | System.out.println('world'); | Add semicolon. | Java |
let b: Int = 'hello' | let b: String = 'hello' | Fix type. | Swift |
[1, 43, 1 | [1, 43, 1] | Close bracket. | Ruby |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(77); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(77, () => console.log('listening')); | Add callback. | Node.js |
{{"age":"result",}} | {{"age":"result"}} | Remove trailing comma. | JSON |
WHERE email = '92' | WHERE email = 92 | Don't quote integer. | SQL |
function compute(z:string){{return z;}} compute(70); | function compute(z:string){{return z;}} compute('test'); | Pass correct type. | TypeScript |
<ul><li>hello<li>data</ul> | <ul><li>hello</li><li>data</li></ul> | Close li. | HTML |
#header {{ color: red; }} | #header {{ color: red; }} | Correct. | CSS |
DELETE FROM users WHERE name=83 | DELETE FROM users WHERE name=83; | Add semicolon. | SQL |
for (c in data) | for (c of data) | for...in iterates keys. | JavaScript |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
$data[65] | if ($data.Count -gt 65) {{ $data[65] }} | Check bounds. | PowerShell |
SELECT * FROM orders WHRE status=97; | SELECT * FROM orders WHERE status=97; | Fix WHERE. | SQL |
if count = 75 | if count == 75 | Use ==. | Go |
if bar > 100
print('hello') | if bar > 100:
print('hello') | Colon missing after if. | Python |
class Product {{ int result; }}
obj.result=5; | class Product {{ public int result; }}
obj.result=5; | Make field public. | Java |
disp('test') | disp('test') | Correct. | MATLAB |
let temp: i32 = "value"; | let temp: &str = "value"; | Type mismatch. | Rust |
.Person {{ color: blue; }} | .Person {{ color: blue; }} | Correct. | CSS |
<div><p>data</div></p> | <div><p>data</p></div> | Nest properly. | HTML |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
y > 1 & x < 97 | y > 1 and x < 97 | Use 'and' not '&'. | Python |
if (num = 21) | if (num == 21) | Use ==. | C++ |
bar | bar() | Add parentheses. | Swift |
String index = 'world'; | String index = "world"; | Double quotes. | Java |
50data = 10 | data50 = 10 | Variable cannot start with digit. | Python |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
<div><p>message</div></p> | <div><p>message</p></div> | Nest properly. | HTML |
$items[19] = 5; | if (isset($items[19])) $items[19] = 5; | Check existence. | PHP |
if (foo = 70) {{}} | if (foo == 70) {{}} | Use ==. | Kotlin |
if (result = 86) | if (result == 86) | Use ==. | R |
function render() {{ echo 'data'; }} | function render() {{ echo 'data'; }} | Correct. | PHP |
re.sqrt(84) | import re
re.sqrt(84) | Import module first. | Python |
temp = 1 | temp=1 | No spaces. | Shell |
<ul><li>test<li>hello</ul> | <ul><li>test</li><li>hello</li></ul> | Close li. | HTML |
let msg = String::from("hello"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("hello"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
var x int = 'result' | var x string = 'result' | Type mismatch. | Go |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
$data = 5; if ($data = 5) {{}} | $data = 5; if ($data == 5) {{}} | Use ==. | PHP |
a > 27 & a < 98 | a > 27 and a < 98 | Use 'and' not '&'. | Python |
fn handle() -> i32 {{ 12 }} | fn handle() -> i32 {{ 12 }} | Correct. | Rust |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.