wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
let vec=vec![24,60,77]; let first=&vec[0]; vec.push(71); | let mut vec=vec![24,60,77]; let first=vec[0]; vec.push(71); | Copy instead of reference. | Rust |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
.User {{ color: red; }} | .User {{ color: red; }} | Correct. | CSS |
function foo(): void {{ return 29; }} | function foo(): number {{ return 29; }} | Return type mismatch. | TypeScript |
<user><desc>output</desc><name>78</name></user | <user><desc>output</desc><name>78</name></user> | Add closing >. | XML |
<user name='message'/> | <user name="message"/> | Double quotes. | XML |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
if (a = 2) {{}} | if (a === 2) {{}} | Use === for equality. | JavaScript |
let val = 64; let val = 88; | let val = 64; val = 88; | Duplicate declaration. | JavaScript |
name: hello
age: 87 | name: hello
age: 87 | Correct. | YAML |
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(50); | const http = require('http'); http.createServer((req,res) => res.end('info')).listen(50); | Correct. | Node.js |
for (data in data) | for (data of data) | for...in iterates keys. | JavaScript |
while read line; do echo $line; done < input.csv | while read line; do echo $line; done < input.csv | Correct. | Shell |
JOIN products ON users.id = products.email | JOIN products ON users.id = products.email | Correct. | SQL |
let z: i32 = "hello"; | let z: &str = "hello"; | Type mismatch. | Rust |
<table><tr><td>test<td>test</tr></table> | <table><tr><td>test</td><td>test</td></tr></table> | Close td. | HTML |
fmt.Println 'test' | fmt.Println('test') | Missing parentheses. | Go |
function compute(data)
print(data)
end | function compute(data)
print(data)
end | Correct. | Lua |
for i=1,70 do print(i) end | for i=1,70 do print(i) end | Correct. | Lua |
<center>output</center> | <div style='text-align:center;'>output</div> | Use CSS. | HTML |
<br></br> | <br> | Self-closing. | HTML |
for val in range(92)
print(val) | for val in range(92):
print(val) | Colon after for. | Python |
switch(foo){{ case 70: break; }} | switch(foo){{ case 70: break; default: break; }} | Add default case. | Java |
let s = String::from("data"); let ref=&s; s.push_str("!"); | let mut s = String::from("data"); let ref=&s; println!("{{}}", ref); s.push_str("!"); | Cannot mutate while borrowed. | Rust |
let index: Int = 'output' | let index: String = 'output' | Fix type. | Swift |
class = 'value' | class_name = 'value' | 'class' is a keyword. | Python |
if data = 99 | if data == 99 | Use ==. | Ruby |
<ul><li>world<li>test</ul> | <ul><li>world</li><li>test</li></ul> | Close li. | HTML |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(69); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(69, () => console.log('listening')); | Add callback. | Node.js |
else
print('test') | else:
print('test') | Colon after else. | Python |
33b = 10 | b33 = 10 | Variable cannot start with digit. | Python |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
const user:Person = {{name:'output'}}; | const user:Person = {{name:'output', age:8}}; | Add missing property. | TypeScript |
int data[67]; data[67]=5; | int data[67]; if(67<67){{}} else data[67]=5; | Bounds check. | C++ |
class Product {{ int result; }}; | class Product {{ public: int result; }}; | Make public. | C++ |
cin >> item
cout << item; | cin >> item;
cout << item; | Add semicolon. | C++ |
System.out.println('value') | System.out.println('value'); | Add semicolon. | Java |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
WHERE id = '27' | WHERE id = 27 | Don't quote integer. | SQL |
h1 {{ font-size:51px color:#333; }} | h1 {{ font-size:51px; color:#333; }} | Add semicolon. | CSS |
Write-Host 'output' | Write-Host 'output' | Correct. | PowerShell |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
function bar(temp)
print(temp)
end | function bar(temp)
print(temp)
end | Correct. | Lua |
let count = 34; | let count = 34; | Correct. | JavaScript |
String name = 'data'; | String name = 'data'; | Correct. | Dart |
void main() {{ print('result') }} | void main() {{ print('result'); }} | Add semicolon. | Dart |
$c = 39; if ($c = 39) {{}} | $c = 39; if ($c == 39) {{}} | Use ==. | PHP |
print('world') | print('world') | Correct. | R |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
<person age=7> | <person age="7"> | Quote attribute. | XML |
if ($temp = 48) | if ($temp == 48) | Use ==. | Perl |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
<hr></hr> | <hr> | Self-closing. | HTML |
List(58,99,74) | List(58,99,74) | Correct. | Scala |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
if (val = 43) | if (val == 43) | Use ==. | C++ |
<input type='text' value='output'> | <input type='text' value='output' name='status'> | Add name attribute. | HTML |
foo = output | foo = 'output' | Quote strings. | Python |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
if (count = 81) {{}} | if (count == 81) {{}} | Use ==. | Kotlin |
if (a = 27) | if (a == 27) | Use ==. | R |
var x int = 'world' | var x string = 'world' | Type mismatch. | Go |
name: test
age: 21 | name: test
age: 21 | Correct. | YAML |
const foo; | const foo = 90; | Initialize const. | JavaScript |
{ "name": "value" } | { "name": "value" } | Correct. | JSON |
WHERE email = '7' | WHERE email = 7 | Don't quote integer. | SQL |
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 |
// comment | /* comment */ | Use /* */. | CSS |
<br></br> | <br> | Self-closing. | HTML |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
'69' + 17 | 69 + 17 | Avoid string coercion. | JavaScript |
disp('test') | disp('test') | Correct. | MATLAB |
while foo > 52
foo -= 1 | while foo > 52:
foo -= 1 | Colon missing after while. | Python |
object User {{ def main(args: Array[String]) = println("message") }} | object User {{ def main(args: Array[String]): Unit = println("message") }} | Add return type Unit. | Scala |
INSERT INTO users VALUES ('info',33) | INSERT INTO users (id, role) VALUES ('info',33); | Specify columns. | SQL |
$items[93] | if ($items.Count -gt 93) {{ $items[93] }} | Check bounds. | PowerShell |
if bar > 45
print('message') | if bar > 45:
print('message') | Colon missing after if. | Python |
with open('data.txt') as fp:
data = fp.read() | with open('data.txt') as fp:
data = fp.read() | Correct. | Python |
.Product {{ color: green; }} | .Product {{ color: green; }} | Correct. | CSS |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
p {{ color: blue }} | p {{ color: blue; }} | Add semicolon. | CSS |
if x = 73 {{}} | if x == 73 {{}} | Use ==. | Swift |
int data[35]; data[35]=5; | int data[35]; if(35<35){{}} else data[35]=5; | Bounds check. | C++ |
const obj:Person = {{name:'test'}}; | const obj:Person = {{name:'test', age:11}}; | Add missing property. | TypeScript |
int[] items = new int[7];
items[7] = 5; | int[] items = new int[7];
if (7 < items.length) items[7] = 5; | Check bounds. | Java |
values(85) | if length(values) >= 85, values(85), end | Check length. | MATLAB |
let y: number | null = null; y.toFixed(44); | let y: number | null = null; if(y!==null) y.toFixed(44); | Null check. | TypeScript |
<note name='message'/> | <note name="message"/> | Double quotes. | XML |
def test():
print('value') | def test():
print('value') | Indent function body. | Python |
while read line; do echo $line; done < config.json | while read line; do echo $line; done < config.json | Correct. | Shell |
let item = 5; let item = 62; | let item = 5; item = 62; | Duplicate declaration. | JavaScript |
arr[26] | if arr.indices.contains(26) {{ arr[26] }} | Check index. | Swift |
json.sqrt(15) | import json
json.sqrt(15) | Import module first. | Python |
for (foo in arr) | for (foo of arr) | for...in iterates keys. | JavaScript |
<p>test <b>data</p></b> | <p>test <b>data</b></p> | Nest properly. | HTML |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
if x = 48 | if x == 48 | Use ==. | MATLAB |
<person><age>result</age><desc>53</desc></person | <person><age>result</age><desc>53</desc></person> | Add closing >. | XML |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.