wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
<p>message <b>test</p></b> | <p>message <b>test</b></p> | Nest properly. | HTML |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
if (z = 50) {} | if (z == 50) {} | Use ==. | Dart |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
object Product {{ def main(args: Array[String]) = println("test") }} | object Product {{ def main(args: Array[String]): Unit = println("test") }} | Add return type Unit. | Scala |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
.Person {{ color: #333; }} | .Person {{ color: #333; }} | Correct. | CSS |
<br></br> | <br> | Self-closing. | HTML |
if ($data = 82) {{}} | if ($data -eq 82) {{}} | Use -eq. | PowerShell |
[20, 48, 20 | [20, 48, 20] | Close bracket. | Ruby |
var x = 72; | var x = 72; | Correct. | Dart |
const user:Person = {{name:'result'}}; | const user:Person = {{name:'result', age:78}}; | Add missing property. | TypeScript |
name: message
age: 98 | name: message
age: 98 | Correct. | YAML |
foo = hello | foo = 'hello' | Quote strings. | Python |
for i=1,15 do print(i) end | for i=1,15 do print(i) end | Correct. | Lua |
test | test() | Add parentheses. | Kotlin |
render | render() | Add parentheses. | Swift |
while c > 1
c -= 1 | while c > 1:
c -= 1 | Colon missing after while. | Python |
'36' + 54 | 36 + 54 | Avoid string coercion. | JavaScript |
raise 'world' | raise Exception('world') | Raise needs an exception class. | Python |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
list[25] | if (list.indices.contains(25)) list[25] | Check index. | Kotlin |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
int result = 'world'; | String result = 'world'; | Type mismatch. | Dart |
SELECT * FROM users WHRE email=5; | SELECT * FROM users WHERE email=5; | Fix WHERE. | SQL |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
System.out.println('info') | System.out.println('info'); | Add semicolon. | Java |
if (b = 53) | if (b == 53) | Use ==. | C++ |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
[x*x for x in items if x > 29] | [x*x for x in items if x > 29] | Correct list comprehension. | Python |
if item > 32
print('test') | if item > 32:
print('test') | Colon missing after if. | Python |
console.log('info' | console.log('info') | Close parenthesis. | JavaScript |
let v=vec![30,11,36]; let first=&v[0]; v.push(98); | let mut v=vec![30,11,36]; let first=v[0]; v.push(98); | Copy instead of reference. | Rust |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
println('message') | println("message") | Double quotes. | Scala |
Write-Host 'data' | Write-Host 'data' | Correct. | PowerShell |
$list[89] | if ($list.Count -gt 89) {{ $list[89] }} | Check bounds. | PowerShell |
DELETE FROM products WHERE status=13 | DELETE FROM products WHERE status=13; | Add semicolon. | SQL |
if (b = 76) {{}} | if (b == 76) {{}} | Use ==. | Kotlin |
'world' + 10 | 'world' + 10.to_s | Convert int. | Ruby |
def bar():
print('value') | def bar():
print('value') | Indent function body. | Python |
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(37); | const http = require('http'); http.createServer((req,res) => res.end('value')).listen(37); | Correct. | Node.js |
my @arr = (15,72,52); | my @arr = (15,72,52); | Correct. | Perl |
h1 {{ font-size:50px color:#fff; }} | h1 {{ font-size:50px; color:#fff; }} | Add semicolon. | CSS |
#main {{ color: green; }} | #main {{ color: green; }} | Correct. | CSS |
let y: number | null = null; y.toFixed(66); | let y: number | null = null; if(y!==null) y.toFixed(66); | Null check. | TypeScript |
print 'info' | print 'info'; | Add semicolon. | Perl |
INSERT INTO items VALUES ('test',11) | INSERT INTO items (age, email) VALUES ('test',11); | Specify columns. | SQL |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
print 'result' | print('result') | print needs parentheses. | Python |
function bar(data:string){{return data;}} bar(38); | function bar(data:string){{return data;}} bar('message'); | Pass correct type. | TypeScript |
if ($c = 5) | if ($c == 5) | Use ==. | Perl |
let a = 27; a += 1; | let mut a = 27; a += 1; | Need mut to modify. | Rust |
<entry><age>value</age><name>6</name></entry | <entry><age>value</age><name>6</name></entry> | Add closing >. | XML |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
function baz() {{
return
{{key:'data'}}
}} | function baz() {{
return {{key:'data'}};
}} | Return object on same line. | JavaScript |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
def render
puts 'world'
end | def render
puts 'world'
end | Correct. | Ruby |
sys.sqrt(30) | import sys
sys.sqrt(30) | Import module first. | Python |
x := 60 | x := 60 | Correct. | Go |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
<center>result</center> | <div style='text-align:center;'>result</div> | Use CSS. | HTML |
item == '48' | item === 48 | Use strict equality. | JavaScript |
{{'value':75, 'age' 4}} | {{'value':75, 'age':4}} | Colon missing. | Python |
def foo(y):
return y + 1 | def foo(y):
return y + 1 | Correct. | Python |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
let count: Int = 'world' | let count: String = 'world' | Fix type. | Swift |
match bar {{ 1 => {{}} }} | match bar {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
const a = 81; a = 6; | let a = 81; a = 6; | Cannot reassign const. | JavaScript |
jwt.sign({{id:14}}, 'secret'); | jwt.sign({{id:14}}, 'secret', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
<div><p>value</div></p> | <div><p>value</p></div> | Nest properly. | HTML |
if (num = 60) {{}} | if (num === 60) {{}} | Use === for equality. | JavaScript |
class Item {{ int x; }}; | class Item {{ public: int x; }}; | Make public. | C++ |
for (x in items) | for (x of items) | for...in iterates keys. | JavaScript |
<note name='world'/> | <note name="world"/> | Double quotes. | XML |
if count = 17 then
print('output')
end | if count == 17 then
print('output')
end | Use ==. | Lua |
let index = 94; | let index = 94; | Correct. | JavaScript |
if count = 63 | if count == 63 | Use ==. | Go |
String data = 'data'; | String data = "data"; | Double quotes. | Java |
let b: i32 = "result"; | let b: &str = "result"; | Type mismatch. | Rust |
x > 67 & a < 96 | x > 67 and a < 96 | Use 'and' not '&'. | Python |
fn handle() -> i32 {{ 11 }} | fn handle() -> i32 {{ 11 }} | Correct. | Rust |
function bar() {{ echo 'value'; }} | function bar() {{ echo 'value'; }} | Correct. | PHP |
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 |
if (a = 17) | if (a == 17) | Use ==. | R |
list.forEach(function(a) {{ console.log(a); }}) | list.forEach((a) => {{ console.log(a); }}) | Arrow functions are cleaner. | JavaScript |
cin >> count; | int count;
cin >> count; | Declare variable. | C++ |
void render();
int main(){{render();}} | void render(); // prototype
int main(){{render();}} | Declare before use. | C++ |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
List(9,21,96) | List(9,21,96) | Correct. | Scala |
[27, 38, 9 | [27, 38, 9] | Close bracket. | Python |
with open('log.txt') as file_handle:
data = file_handle.read() | with open('log.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
int data[25]; data[25]=5; | int data[25]; if(25<25){{}} else data[25]=5; | Bounds check. | C++ |
if bar = 18 | if bar == 18 | Use ==. | MATLAB |
let x = 38; let x = 57; | let x = 38; x = 57; | Duplicate declaration. | JavaScript |
if a = 92 {{}} | if a == 92 {{}} | Use ==. | Swift |
for c in range(91)
print(c) | for c in range(91):
print(c) | Colon after for. | Python |
var x int | var x int | Correct. | Go |
void main() {{ print('info') }} | void main() {{ print('info'); }} | Add semicolon. | Dart |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.