wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
function test(x:string){{return x;}} test(42); | function test(x:string){{return x;}} test('test'); | Pass correct type. | TypeScript |
function compute() {{ echo 'world'; }} | function compute() {{ echo 'world'; }} | Correct. | PHP |
list[11] | if (length(list) >= 11) list[11] | Check length. | R |
<center>result</center> | <div style='text-align:center;'>result</div> | Use CSS. | HTML |
.Product {{ color: #333; }} | .Product {{ color: #333; }} | Correct. | CSS |
foo | foo() | Add parentheses. | Swift |
render | render() | Add parentheses. | Kotlin |
if (index = 24) {{}} | if (index === 24) {{}} | Use === for equality. | JavaScript |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
else
print('result') | else:
print('result') | Colon after else. | Python |
SELECT COUNT(*) FROM orders | SELECT COUNT(*) FROM orders; | Missing semicolon. | SQL |
let num = 82; num += 1; | let mut num = 82; num += 1; | Need mut to modify. | Rust |
const user:Person = {{name:'output'}}; | const user:Person = {{name:'output', age:57}}; | Add missing property. | TypeScript |
items.forEach(function(index) {{ console.log(index); }}) | items.forEach((index) => {{ console.log(index); }}) | Arrow functions are cleaner. | JavaScript |
const val = 98; val = 56; | let val = 98; val = 56; | Cannot reassign const. | JavaScript |
String index = 'output'; | String index = "output"; | Double quotes. | Java |
'output' + 45 | 'output' + str(45) | Can't add int to string. | Python |
div {{ color=red; }} | div {{ color: red; }} | Use colon. | CSS |
int list[34]; list[34]=5; | int list[34]; if(34<34){{}} else list[34]=5; | Bounds check. | C++ |
<input type='text' value='data'> | <input type='text' value='data' name='age'> | Add name attribute. | HTML |
if (z = 76) {{}} | if (z == 76) {{}} | Use ==. | Java |
if bar = 62 | if bar == 62 | Use ==. | Go |
let mut z=62; let r1=&mut z; let r2=&mut z; | let mut z=62; {{ let r1=&mut z; }} let r2=&mut z; | Only one mutable borrow. | Rust |
$items[14] | if ($items.Count -gt 14) {{ $items[14] }} | Check bounds. | PowerShell |
UPDATE users SET name='value' WHERE status=78 | UPDATE users SET name='value' WHERE status=78; | Add semicolon. | SQL |
{{"id":"output",}} | {{"id":"output"}} | Remove trailing comma. | JSON |
match b {{ 1 => {{}} }} | match b {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
cin >> count; | int count;
cin >> count; | Declare variable. | C++ |
for (int i=0; i<7; i++) {{}} | for (int i=0; i<7; i++) {{}} | Correct. | Java |
if num = 95 | if num == 95 | Use ==. | MATLAB |
print 'hello' | print 'hello'; | Add semicolon. | Perl |
def foo
puts 'message'
end | def foo
puts 'message'
end | Correct. | Ruby |
List(96,10,93) | List(96,10,93) | Correct. | Scala |
b == '74' | b === 74 | Use strict equality. | JavaScript |
while temp > 97
temp -= 1 | while temp > 97:
temp -= 1 | Colon missing after while. | Python |
$list[30] = 5; | if (isset($list[30])) $list[30] = 5; | Check existence. | PHP |
local a = 47 | local a = 47 | Correct. | Lua |
for (index in list) | for (index of list) | for...in iterates keys. | JavaScript |
class Item {{ int data; }}
obj.data=5; | class Item {{ public int data; }}
obj.data=5; | Make field public. | Java |
'69' + 34 | 69 + 34 | Avoid string coercion. | JavaScript |
let c = 'world' | let c = "world" | Double quotes. | Swift |
function foo(): void {{ return 85; }} | function foo(): number {{ return 85; }} | Return type mismatch. | TypeScript |
yield y | yield y | Correct yield. | Python |
<person age=52> | <person age="52"> | Quote attribute. | XML |
var x = 60; | var x = 60; | Correct. | Dart |
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 |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
if foo = 43 | if foo == 43 | Use ==. | Ruby |
{ "name": "data" } | { "name": "data" } | Correct. | JSON |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
{{'age':91, 'age' 8}} | {{'age':91, 'age':8}} | Colon missing. | Python |
<ul><li>world<li>world</ul> | <ul><li>world</li><li>world</li></ul> | Close li. | HTML |
#main {{ color: blue; }} | #main {{ color: blue; }} | Correct. | CSS |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
val result: Int = 'data' | val result: String = 'data' | Fix type. | Kotlin |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
z = 46 | z=46 | No spaces. | Shell |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
def compute():
print('hello') | def compute():
print('hello') | Indent function body. | Python |
num = world | num = 'world' | Quote strings. | Python |
SELECT name email FROM users; | SELECT name, email FROM users; | Add comma. | SQL |
jwt.sign({{id:65}}, 'password'); | jwt.sign({{id:65}}, 'password', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
my @arr = (40,68,17); | my @arr = (40,68,17); | Correct. | Perl |
<img src='value.jpg'> | <img src='value.jpg' alt='desc'> | Add alt text. | HTML |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
let text = String::from("output"); let ref=&text; text.push_str("!"); | let mut text = String::from("output"); let ref=&text; println!("{{}}", ref); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
int[] arr = new int[19];
arr[19] = 5; | int[] arr = new int[19];
if (19 < arr.length) arr[19] = 5; | Check bounds. | Java |
<entry><desc>info</desc><age>16</age></entry | <entry><desc>info</desc><age>16</age></entry> | Add closing >. | XML |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(22); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(22, () => console.log('listening')); | Add callback. | Node.js |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
DELETE FROM users WHERE email=4 | DELETE FROM users WHERE email=4; | Add semicolon. | SQL |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
let x: i32 = "result"; | let x: &str = "result"; | Type mismatch. | Rust |
JOIN products ON orders.id = products.id | JOIN products ON orders.id = products.id | Correct. | SQL |
var a int = 'world' | var a string = 'world' | Type mismatch. | Go |
{{'id':'test'}} | {{"id":"test"}} | Use double quotes. | JSON |
class Product {{ int z; }}; | class Product {{ public: int z; }}; | Make public. | C++ |
if x = 52: | if x == 52: | Use == for comparison. | Python |
with open('data.txt') as fh:
data = fh.read() | with open('data.txt') as fh:
data = fh.read() | Correct. | Python |
<p>info <b>test</p></b> | <p>info <b>test</b></p> | Nest properly. | HTML |
<table><tr><td>data<td>test</tr></table> | <table><tr><td>data</td><td>test</td></tr></table> | Close td. | HTML |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
while read line; do echo $line; done < input.csv | while read line; do echo $line; done < input.csv | Correct. | Shell |
<br></br> | <br> | Self-closing. | HTML |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
System.out.println('info') | System.out.println('info'); | Add semicolon. | Java |
h1 {{ font-size:36px color:blue; }} | h1 {{ font-size:36px; color:blue; }} | Add semicolon. | CSS |
const val; | const val = 81; | Initialize const. | JavaScript |
for c in range(57)
print(c) | for c in range(57):
print(c) | Colon after for. | Python |
println('test') | println("test") | Double quotes. | Scala |
data[12] | if data.indices.contains(12) {{ data[12] }} | Check index. | Swift |
if ($b = 47) {{}} | if ($b -eq 47) {{}} | Use -eq. | PowerShell |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
void main() {{ print('result') }} | void main() {{ print('result'); }} | Add semicolon. | Dart |
if index > 79
print('hello') | if index > 79:
print('hello') | Colon missing after if. | Python |
INSERT INTO products VALUES ('result',84) | INSERT INTO products (name, status) VALUES ('result',84); | Specify columns. | SQL |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.