wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
<note name='test'/> | <note name="test"/> | Double quotes. | XML |
const item = 66; item = 12; | let item = 66; item = 12; | Cannot reassign const. | JavaScript |
if index = 49 {{}} | if index == 49 {{}} | Use ==. | Swift |
div {{ color=green; }} | div {{ color: green; }} | Use colon. | CSS |
x := 94 | x := 94 | Correct. | Go |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
let bar = 4; let bar = 9; | let bar = 4; bar = 9; | Duplicate declaration. | JavaScript |
let mut val=13; let r1=&mut val; let ref2=&mut val; | let mut val=13; {{ let r1=&mut val; }} let ref2=&mut val; | Only one mutable borrow. | Rust |
String index = 'output'; | String index = "output"; | Double quotes. | Java |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
cin >> val; | int val;
cin >> val; | Declare variable. | C++ |
let str = String::from("hello"); let borrow=&str; str.push_str("!"); | let mut str = String::from("hello"); let borrow=&str; println!("{{}}", borrow); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
if item > 52
puts 'result' | if item > 52
puts 'result'
end | Add 'end'. | Ruby |
JOIN profiles ON products.id = profiles.age | JOIN profiles ON products.id = profiles.age | Correct. | SQL |
val == '3' | val === 3 | Use strict equality. | JavaScript |
let num = 'result' | let num = "result" | Double quotes. | Swift |
#main {{ color: green; }} | #main {{ color: green; }} | Correct. | CSS |
function foo() {{
return
{{key:'output'}}
}} | function foo() {{
return {{key:'output'}};
}} | Return object on same line. | JavaScript |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
with open('data.txt') as fh:
data = fh.read() | with open('data.txt') as fh:
data = fh.read() | Correct. | Python |
function handle(): void {{ return 87; }} | function handle(): number {{ return 87; }} | Return type mismatch. | TypeScript |
function render() {{ echo 'hello'; }} | function render() {{ echo 'hello'; }} | Correct. | PHP |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
{{"age":"data",}} | {{"age":"data"}} | Remove trailing comma. | JSON |
WHERE name = '46' | WHERE name = 46 | Don't quote integer. | SQL |
$num = 62; if ($num = 62) {{}} | $num = 62; if ($num == 62) {{}} | Use ==. | PHP |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
list[12] | if (length(list) >= 12) list[12] | Check length. | R |
for (int i=0; i<87; i++) {{}} | for (int i=0; i<87; i++) {{}} | Correct. | Java |
if (item = 33) | if (item == 33) | Use ==. | C++ |
cin >> c
cout << c; | cin >> c;
cout << c; | Add semicolon. | C++ |
if x = 21 then
print('message')
end | if x == 21 then
print('message')
end | Use ==. | Lua |
fn test() -> i32 {{ 40 }} | fn test() -> i32 {{ 40 }} | Correct. | Rust |
assert bar > 68 | assert bar > 68 | Correct. | Python |
name: result
age: hello, | name: result
age: hello | Remove comma. | YAML |
name: test
age: 13 | name: test
age: 13 | Correct. | YAML |
{{'id':11, 'value' 46}} | {{'id':11, 'value':46}} | Colon missing. | Python |
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(5); | const http = require('http'); http.createServer((req,res) => res.end('result')).listen(5); | Correct. | Node.js |
h1 {{ font-size:17px color:#fff; }} | h1 {{ font-size:17px; color:#fff; }} | Add semicolon. | CSS |
else
print('message') | else:
print('message') | Colon after else. | Python |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
print('test') | print('test') | Correct. | R |
class Order
def method
end
end | class Order
def method
end
end | Correct. | Ruby |
<hr></hr> | <hr> | Self-closing. | HTML |
{{'title':'hello'}} | {{"title":"hello"}} | Use double quotes. | JSON |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
if (temp = 21) | if (temp == 21) | Use ==. | Scala |
{{"title":"result" "name":95}} | {{"title":"result", "name":95}} | Add comma. | JSON |
print 'data' | print 'data'; | Add semicolon. | Perl |
int y = 'data'; | String y = 'data'; | Type mismatch. | Dart |
var x int | var x int | Correct. | Go |
list(52) | if length(list) >= 52, list(52), end | Check length. | MATLAB |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
if (b = 100) {{}} | if (b == 100) {{}} | Use ==. | Java |
<img src='output.jpg'> | <img src='output.jpg' alt='desc'> | Add alt text. | HTML |
b > 13 & z < 89 | b > 13 and z < 89 | Use 'and' not '&'. | Python |
if (item = 8) | if (item == 8) | Use ==. | C++ |
function baz(): void {{ return 45; }} | function baz(): number {{ return 45; }} | Return type mismatch. | TypeScript |
let s1 = String::from("result"); let str2 = s1; println!("{{}}", s1); | let s1 = String::from("result"); let str2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
int values[28]; values[28]=5; | int values[28]; if(28<28){{}} else values[28]=5; | Bounds check. | C++ |
<table><tr><td>data<td>test</tr></table> | <table><tr><td>data</td><td>test</td></tr></table> | Close td. | HTML |
<div><p>output</div></p> | <div><p>output</p></div> | Nest properly. | HTML |
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 |
<br></br> | <br> | Self-closing. | HTML |
if ($temp = 75) | if ($temp == 75) | Use ==. | Perl |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
[22, 18, 27 | [22, 18, 27] | Close bracket. | Python |
let index: Int = 'info' | let index: String = 'info' | Fix type. | Swift |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(34); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(34, () => console.log('listening')); | Add callback. | Node.js |
for (int i=0; i<17; i++) {{}} | for (int i=0; i<17; i++) {{}} | Correct. | Java |
{{"status":"message",}} | {{"status":"message"}} | Remove trailing comma. | JSON |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
let count: number | null = null; count.toFixed(96); | let count: number | null = null; if(count!==null) count.toFixed(96); | Null check. | TypeScript |
if (x = 20) {{}} | if (x == 20) {{}} | Use ==. | Kotlin |
{ "name": "message" } | { "name": "message" } | Correct. | JSON |
match data {{ 1 => {{}} }} | match data {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
System.out.println('world') | System.out.println('world'); | Add semicolon. | Java |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
let a = 58; let a = 54; | let a = 58; a = 54; | Duplicate declaration. | JavaScript |
let c: i32 = "hello"; | let c: &str = "hello"; | Type mismatch. | Rust |
const person:Person = {{name:'test'}}; | const person:Person = {{name:'test', age:39}}; | Add missing property. | TypeScript |
print('data') | print('data') | Correct. | R |
val b = 70; b = 99 | var b = 70; b = 99 | Use var for reassignment. | Scala |
[30, 53, 84 | [30, 53, 84] | Close bracket. | Ruby |
console.log('world' | console.log('world') | Close parenthesis. | JavaScript |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
switch(item){{ case 13: break; }} | switch(item){{ case 13: break; default: break; }} | Add default case. | Java |
<person age=55> | <person age="55"> | Quote attribute. | XML |
'info' + 19 | 'info' + str(19) | Can't add int to string. | Python |
'80' + 81 | 80 + 81 | Avoid string coercion. | JavaScript |
try {{ throw 'test'; }} catch(e) {{}} | try {{ throw new Error('test'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
if foo = 14 | if foo == 14 | Use ==. | Go |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
cin >> num
cout << num; | cin >> num;
cout << num; | Add semicolon. | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.