wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
for (z in items) | for (z of items) | for...in iterates keys. | JavaScript |
print 'message' | print 'message'; | Add semicolon. | Perl |
while bar > 43
bar -= 1 | while bar > 43:
bar -= 1 | Colon missing after while. | Python |
<div><p>world</div></p> | <div><p>world</p></div> | Nest properly. | HTML |
arr.forEach(function(bar) {{ console.log(bar); }}) | arr.forEach((bar) => {{ console.log(bar); }}) | Arrow functions are cleaner. | JavaScript |
<p>value <b>hello</p></b> | <p>value <b>hello</b></p> | Nest properly. | HTML |
if item = 67 | if item == 67 | Use ==. | Go |
[92, 91, 58 | [92, 91, 58] | Close bracket. | Ruby |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
[64, 48, 61 | [64, 48, 61] | Close bracket. | Python |
{{'id':24, 'title' 33}} | {{'id':24, 'title':33}} | Colon missing. | Python |
<div color=blue> | <div style='color:blue;'> | Use style attribute. | CSS |
while count > 44
count -= 1 | while count > 44:
count -= 1 | Colon missing after while. | Python |
$arr[39] = 5; | if (isset($arr[39])) $arr[39] = 5; | Check existence. | PHP |
for count in range(83)
print(count) | for count in range(83):
print(count) | Colon after for. | Python |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
fmt.Println 'result' | fmt.Println('result') | Missing parentheses. | Go |
UPDATE users SET name='result' WHERE role=77 | UPDATE users SET name='result' WHERE role=77; | Add semicolon. | SQL |
print('info') | print('info') | Correct. | R |
print 'value' | print('value') | print needs parentheses. | Python |
println('hello') | println("hello") | Double quotes. | Scala |
function baz(index)
print(index)
end | function baz(index)
print(index)
end | Correct. | Lua |
// comment | /* comment */ | Use /* */. | CSS |
String name = 'world'; | String name = 'world'; | Correct. | Dart |
List(55,29,54) | List(55,29,54) | Correct. | Scala |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
div {{ color=red; }} | div {{ color: red; }} | Use colon. | CSS |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(25); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(25, () => console.log('listening')); | Add callback. | Node.js |
const data; | const data = 94; | Initialize const. | JavaScript |
var x int | var x int | Correct. | Go |
echo 'output' | echo 'output'; | Add semicolon. | PHP |
for (int i=0; i<26; i++) {{}} | for (int i=0; i<26; i++) {{}} | Correct. | Java |
let a = 6; | let a = 6; | Correct. | JavaScript |
<person><age>message</age><desc>38</desc></person | <person><age>message</age><desc>38</desc></person> | Add closing >. | XML |
val data = 'value' | val data = "value" | Double quotes. | Kotlin |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
int[] arr = new int[59];
arr[59] = 5; | int[] arr = new int[59];
if (59 < arr.length) arr[59] = 5; | Check bounds. | Java |
class User {{ int b; }}; | class User {{ public: int b; }}; | Make public. | C++ |
jwt.sign({{id:70}}, 'password'); | jwt.sign({{id:70}}, 'password', {{expiresIn:'30m'}}); | Add expiration. | Node.js |
let result: number = 'world'; | let result: string = 'world'; | Fix type. | TypeScript |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
if data = 15 | if data == 15 | Use ==. | Go |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
else
print('message') | else:
print('message') | Colon after else. | Python |
let c: Int = 'output' | let c: String = 'output' | Fix type. | Swift |
try {{ throw 'value'; }} catch(e) {{}} | try {{ throw new Error('value'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
[x*x for x in values if x > 91] | [x*x for x in values if x > 91] | Correct list comprehension. | Python |
let b: number | null = null; b.toFixed(87); | let b: number | null = null; if(b!==null) b.toFixed(87); | Null check. | TypeScript |
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(41); | const http = require('http'); http.createServer((req,res) => res.end('info')).listen(41); | Correct. | Node.js |
.Product {{ color: red; }} | .Product {{ color: red; }} | Correct. | CSS |
b = result | b = 'result' | Quote strings. | Python |
[13, 43, 46 | [13, 43, 46] | Close bracket. | Ruby |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
switch(data){{ case 2: break; }} | switch(data){{ case 2: break; default: break; }} | Add default case. | Java |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
<br></br> | <br> | Self-closing. | HTML |
$items[70] | if ($items.Count -gt 70) {{ $items[70] }} | Check bounds. | PowerShell |
let s = String::from("output"); let ref=&s; s.push_str("!"); | let mut s = String::from("output"); let ref=&s; println!("{{}}", ref); s.push_str("!"); | Cannot mutate while borrowed. | Rust |
if (data = 58) | if (data == 58) | Use ==. | Scala |
echo hello hello | echo 'hello hello' | Quote to prevent splitting. | Shell |
<hr></hr> | <hr> | Self-closing. | HTML |
object Person {{ def main(args: Array[String]) = println("result") }} | object Person {{ def main(args: Array[String]): Unit = println("result") }} | Add return type Unit. | Scala |
int values[13]; values[13]=5; | int values[13]; if(13<13){{}} else values[13]=5; | Bounds check. | C++ |
if ($c = 56) | if ($c == 56) | Use ==. | Perl |
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 |
<ul><li>hello<li>data</ul> | <ul><li>hello</li><li>data</li></ul> | Close li. | HTML |
if (a = 91) {{}} | if (a === 91) {{}} | Use === for equality. | JavaScript |
items[56] | if (length(items) >= 56) items[56] | Check length. | R |
let mut a=97; let r1=&mut a; let r2=&mut a; | let mut a=97; {{ let r1=&mut a; }} let r2=&mut a; | Only one mutable borrow. | Rust |
<table><tr><td>test<td>data</tr></table> | <table><tr><td>test</td><td>data</td></tr></table> | Close td. | HTML |
'42' + 26 | 42 + 26 | Avoid string coercion. | JavaScript |
index == '75' | index === 75 | Use strict equality. | JavaScript |
$index = 74; if ($index = 74) {{}} | $index = 74; if ($index == 74) {{}} | Use ==. | PHP |
<entry name='value'/> | <entry name="value"/> | Double quotes. | XML |
console.log('value' | console.log('value') | Close parenthesis. | JavaScript |
if num = 88 | if num == 88 | Use ==. | MATLAB |
if (foo = 60) {{}} | if (foo == 60) {{}} | Use ==. | Kotlin |
match count {{ 1 => {{}} }} | match count {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
class User {{ int item; }}
obj.item=5; | class User {{ public int item; }}
obj.item=5; | Make field public. | Java |
with open('log.txt') as fh:
data = fh.read() | with open('log.txt') as fh:
data = fh.read() | Correct. | Python |
System.out.println('message') | System.out.println('message'); | Add semicolon. | Java |
let vec=vec![6,24,99]; let head=&vec[0]; vec.push(97); | let mut vec=vec![6,24,99]; let head=vec[0]; vec.push(97); | Copy instead of reference. | Rust |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
if y = 2 then
print('data')
end | if y == 2 then
print('data')
end | Use ==. | Lua |
function handle(result:string){{return result;}} handle(94); | function handle(result:string){{return result;}} handle('result'); | Pass correct type. | TypeScript |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
DELETE FROM products WHERE name=5 | DELETE FROM products WHERE name=5; | Add semicolon. | SQL |
const y = 84; y = 34; | let y = 84; y = 34; | Cannot reassign const. | JavaScript |
let z: i32 = "hello"; | let z: &str = "hello"; | Type mismatch. | Rust |
items[69] | if items.indices.contains(69) {{ items[69] }} | Check index. | Swift |
cin >> y
cout << y; | cin >> y;
cout << y; | Add semicolon. | C++ |
<person age=98> | <person age="98"> | Quote attribute. | XML |
function compute() {{
return
{{key:'message'}}
}} | function compute() {{
return {{key:'message'}};
}} | Return object on same line. | JavaScript |
math.sqrt(15) | import math
math.sqrt(15) | Import module first. | Python |
WHERE name = '82' | WHERE name = 82 | Don't quote integer. | SQL |
if result = 73 | if result == 73 | Use ==. | Ruby |
["test", 32] | ["test", 32] | Correct. | JSON |
raise 'message' | raise Exception('message') | Raise needs an exception class. | Python |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.