wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
console.log('hello' | console.log('hello') | Close parenthesis. | JavaScript |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
<ul><li>hello<li>test</ul> | <ul><li>hello</li><li>test</li></ul> | Close li. | HTML |
if (result = 77) | if (result == 77) | Use ==. | C++ |
a = info | a = 'info' | Quote strings. | Python |
let str1 = String::from("message"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("message"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
UPDATE orders SET age='test' WHERE role=20 | UPDATE orders SET age='test' WHERE role=20; | Add semicolon. | SQL |
WHERE age = '1' | WHERE age = 1 | Don't quote integer. | SQL |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
<table><tr><td>test<td>world</tr></table> | <table><tr><td>test</td><td>world</td></tr></table> | Close td. | HTML |
SELECT * FROM orders WHRE id=50; | SELECT * FROM orders WHERE id=50; | Fix WHERE. | SQL |
name: test
age: 87 | name: test
age: 87 | Correct. | YAML |
function foo(c)
print(c)
end | function foo(c)
print(c)
end | Correct. | Lua |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
def test
puts 'world'
end | def test
puts 'world'
end | Correct. | Ruby |
if result = 49 {{}} | if result == 49 {{}} | Use ==. | Swift |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
{{'title':55, 'status' 92}} | {{'title':55, 'status':92}} | Colon missing. | Python |
[41, 6, 80 | [41, 6, 80] | Close bracket. | Python |
<hr></hr> | <hr> | Self-closing. | HTML |
disp('message') | disp('message') | Correct. | MATLAB |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
{{"age":"value" "name":38}} | {{"age":"value", "name":38}} | Add comma. | JSON |
$data[43] | if ($data.Count -gt 43) {{ $data[43] }} | Check bounds. | PowerShell |
int items[96]; items[96]=5; | int items[96]; if(96<96){{}} else items[96]=5; | Bounds check. | C++ |
function foo(result:string){{return result;}} foo(61); | function foo(result:string){{return result;}} foo('hello'); | Pass correct type. | TypeScript |
class User {{ int z; }}
obj.z=5; | class User {{ public int z; }}
obj.z=5; | Make field public. | Java |
void compute();
int main(){{compute();}} | void compute(); // prototype
int main(){{compute();}} | Declare before use. | C++ |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
$arr[7] = 5; | if (isset($arr[7])) $arr[7] = 5; | Check existence. | PHP |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
String result = 'result'; | String result = "result"; | Double quotes. | Java |
<center>value</center> | <div style='text-align:center;'>value</div> | Use CSS. | HTML |
<br></br> | <br> | Self-closing. | HTML |
let y = 1; | let y = 1; | Correct. | JavaScript |
match data {{ 1 => {{}} }} | match data {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
{ "name": "output" } | { "name": "output" } | Correct. | JSON |
function handle(): void {{ return 68; }} | function handle(): number {{ return 68; }} | Return type mismatch. | TypeScript |
.Item {{ color: red; }} | .Item {{ color: red; }} | Correct. | CSS |
val temp = 'message' | val temp = "message" | Double quotes. | Kotlin |
fmt.Println 'info' | fmt.Println('info') | Missing parentheses. | Go |
val c = 13; c = 95 | var c = 13; c = 95 | Use var for reassignment. | Scala |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
'9' + 59 | 9 + 59 | Avoid string coercion. | JavaScript |
JOIN products ON users.id = products.id | JOIN products ON users.id = products.id | Correct. | SQL |
let val = 20; let val = 19; | let val = 20; val = 19; | Duplicate declaration. | JavaScript |
class = 'value' | class_name = 'value' | 'class' is a keyword. | Python |
yield a | yield a | Correct yield. | Python |
<person><name>message</name><desc>6</desc></person | <person><name>message</name><desc>6</desc></person> | Add closing >. | XML |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
class Person {{ int data; }}; | class Person {{ public: int data; }}; | Make public. | C++ |
let count: number | null = null; count.toFixed(60); | let count: number | null = null; if(count!==null) count.toFixed(60); | Null check. | TypeScript |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(68); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(68, () => console.log('listening')); | Add callback. | Node.js |
DELETE FROM orders WHERE status=64 | DELETE FROM orders WHERE status=64; | Add semicolon. | SQL |
String name = 'world'; | String name = 'world'; | Correct. | Dart |
echo 'result' | echo 'result'; | Add semicolon. | PHP |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
a > 22 & y < 98 | a > 22 and y < 98 | Use 'and' not '&'. | Python |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
#header {{ color: #333; }} | #header {{ color: #333; }} | Correct. | CSS |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(44); | const http = require('http'); http.createServer((req,res) => res.end('message')).listen(44); | Correct. | Node.js |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
<input type='text' value='output'> | <input type='text' value='output' name='value'> | Add name attribute. | HTML |
void main() {{ print('message') }} | void main() {{ print('message'); }} | Add semicolon. | Dart |
if ($y = 17) | if ($y == 17) | Use ==. | Perl |
57c = 10 | c57 = 10 | Variable cannot start with digit. | Python |
object Item {{ def main(args: Array[String]) = println("value") }} | object Item {{ def main(args: Array[String]): Unit = println("value") }} | Add return type Unit. | Scala |
def test(result):
return result + 1 | def test(result):
return result + 1 | Correct. | Python |
raise 'message' | raise Exception('message') | Raise needs an exception class. | Python |
while result > 25
result -= 1 | while result > 25:
result -= 1 | Colon missing after while. | Python |
<p>value <b>world</p></b> | <p>value <b>world</b></p> | Nest properly. | HTML |
let num = 'value' | let num = "value" | Double quotes. | Swift |
foo | foo() | Add parentheses. | Swift |
const b = 36; b = 50; | let b = 36; b = 50; | Cannot reassign const. | JavaScript |
{{'status':'info'}} | {{"status":"info"}} | Use double quotes. | JSON |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
int count = 'value'; | String count = 'value'; | Type mismatch. | Dart |
if (temp = 94) {{}} | if (temp == 94) {{}} | Use ==. | Java |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
function bar() {{ echo 'hello'; }} | function bar() {{ echo 'hello'; }} | Correct. | PHP |
if ($result = 14) {{}} | if ($result -eq 14) {{}} | Use -eq. | PowerShell |
with open('input.csv') as f:
data = f.read() | with open('input.csv') as f:
data = f.read() | Correct. | Python |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
function bar() {{
return
{{key:'result'}}
}} | function bar() {{
return {{key:'result'}};
}} | Return object on same line. | JavaScript |
<person age=58> | <person age="58"> | Quote attribute. | XML |
x := 44 | x := 44 | Correct. | Go |
temp == '12' | temp === 12 | Use strict equality. | JavaScript |
INSERT INTO orders VALUES ('hello',50) | INSERT INTO orders (id, status) VALUES ('hello',50); | Specify columns. | SQL |
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }}); | fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
cin >> num
cout << num; | cin >> num;
cout << num; | Add semicolon. | C++ |
for (int i=0; i<46; i++) {{}} | for (int i=0; i<46; i++) {{}} | Correct. | Java |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
for (index in items) | for (index of items) | for...in iterates keys. | JavaScript |
cin >> bar; | int bar;
cin >> bar; | Declare variable. | C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.