wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
let c: number | null = null; c.toFixed(35); | let c: number | null = null; if(c!==null) c.toFixed(35); | Null check. | TypeScript |
let b = 9; | let b = 9; | Correct. | JavaScript |
$data[85] = 5; | if (isset($data[85])) $data[85] = 5; | Check existence. | PHP |
cin >> index; | int index;
cin >> index; | Declare variable. | C++ |
os.sqrt(64) | import os
os.sqrt(64) | Import module first. | Python |
const person:Person = {{name:'value'}}; | const person:Person = {{name:'value', age:77}}; | Add missing property. | TypeScript |
WHERE age = '39' | WHERE age = 39 | Don't quote integer. | SQL |
$a = 12; if ($a = 12) {{}} | $a = 12; if ($a == 12) {{}} | Use ==. | PHP |
else
print('output') | else:
print('output') | Colon after else. | Python |
'66' + 68 | 66 + 68 | Avoid string coercion. | JavaScript |
for (int i=0; i<17; i++) {{}} | for (int i=0; i<17; i++) {{}} | Correct. | Java |
y > 75 & a < 65 | y > 75 and a < 65 | Use 'and' not '&'. | Python |
DELETE FROM products WHERE status=27 | DELETE FROM products WHERE status=27; | Add semicolon. | SQL |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
echo 'world' | echo 'world'; | Add semicolon. | PHP |
arr[58] | if arr.indices.contains(58) {{ arr[58] }} | Check index. | Swift |
// comment | /* comment */ | Use /* */. | CSS |
{{'name':57, 'id' 74}} | {{'name':57, 'id':74}} | Colon missing. | Python |
int data[71]; data[71]=5; | int data[71]; if(71<71){{}} else data[71]=5; | Bounds check. | C++ |
with open('data.txt') as fh:
data = fh.read() | with open('data.txt') as fh:
data = fh.read() | Correct. | Python |
if a = 1 | if a == 1 | Use ==. | Ruby |
<img src='output.jpg'> | <img src='output.jpg' alt='desc'> | Add alt text. | HTML |
print 'test' | print('test') | print needs parentheses. | Python |
{{'value':'hello'}} | {{"value":"hello"}} | Use double quotes. | JSON |
function process(b:string){{return b;}} process(72); | function process(b:string){{return b;}} process('output'); | Pass correct type. | TypeScript |
try {{ throw 'message'; }} catch(e) {{}} | try {{ throw new Error('message'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
String b = 'test'; | String b = "test"; | Double quotes. | Java |
let vec=vec![38,88,57]; let first=&vec[0]; vec.push(17); | let mut vec=vec![38,88,57]; let first=vec[0]; vec.push(17); | Copy instead of reference. | Rust |
const y; | const y = 98; | Initialize const. | JavaScript |
disp('message') | disp('message') | Correct. | MATLAB |
<hr></hr> | <hr> | Self-closing. | HTML |
data(46) | if length(data) >= 46, data(46), end | Check length. | MATLAB |
title: info
age: test, | title: info
age: test | Remove comma. | YAML |
class User {{ int b; }}
obj.b=5; | class User {{ public int b; }}
obj.b=5; | Make field public. | Java |
bar = message | bar = 'message' | Quote strings. | Python |
cin >> bar
cout << bar; | cin >> bar;
cout << bar; | Add semicolon. | C++ |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
for x in range(97)
print(x) | for x in range(97):
print(x) | Colon after for. | Python |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
val temp = 'world' | val temp = "world" | Double quotes. | Kotlin |
if c > 4
print('message') | if c > 4:
print('message') | Colon missing after if. | Python |
SELECT id email FROM items; | SELECT id, email FROM items; | Add comma. | SQL |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
UPDATE products SET name='info' WHERE status=13 | UPDATE products SET name='info' WHERE status=13; | Add semicolon. | SQL |
compute | compute() | Add parentheses. | Swift |
for (num in arr) | for (num of arr) | for...in iterates keys. | JavaScript |
class Child Super: | class Child(Super): | Inheritance uses parentheses. | Python |
def foo(z):
return z + 1 | def foo(z):
return z + 1 | Correct. | Python |
my @arr = (60,12,63); | my @arr = (60,12,63); | Correct. | Perl |
void test();
int main(){{test();}} | void test(); // prototype
int main(){{test();}} | Declare before use. | C++ |
match num {{ 1 => {{}} }} | match num {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
function render(): void {{ return 97; }} | function render(): number {{ return 97; }} | Return type mismatch. | TypeScript |
<user name='result'/> | <user name="result"/> | Double quotes. | XML |
[34, 83, 35 | [34, 83, 35] | Close bracket. | Python |
if (foo = 72) {{}} | if (foo == 72) {{}} | Use ==. | Kotlin |
let item = 'info' | let item = "info" | Double quotes. | Swift |
{{"value":"data",}} | {{"value":"data"}} | Remove trailing comma. | JSON |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
let data: number = 'message'; | let data: string = 'message'; | Fix type. | TypeScript |
if a = 81 | if a == 81 | Use ==. | Go |
console.log('data' | console.log('data') | Close parenthesis. | JavaScript |
print('info') | print('info') | Correct. | R |
.User {{ color: #fff; }} | .User {{ color: #fff; }} | Correct. | CSS |
render | render() | Add parentheses. | Kotlin |
[63, 82, 38 | [63, 82, 38] | Close bracket. | Ruby |
items.forEach(function(foo) {{ console.log(foo); }}) | items.forEach((foo) => {{ console.log(foo); }}) | Arrow functions are cleaner. | JavaScript |
{{"age":"output" "value":83}} | {{"age":"output", "value":83}} | Add comma. | JSON |
let mut data=70; let r1=&mut data; let r2=&mut data; | let mut data=70; {{ let r1=&mut data; }} let r2=&mut data; | Only one mutable borrow. | Rust |
<p>data <b>data</p></b> | <p>data <b>data</b></p> | Nest properly. | HTML |
System.out.println('output') | System.out.println('output'); | Add semicolon. | Java |
'message' + 34 | 'message' + str(34) | Can't add int to string. | Python |
<ul><li>world<li>test</ul> | <ul><li>world</li><li>test</li></ul> | Close li. | HTML |
if (bar = 2) | if (bar == 2) | Use ==. | R |
if c = 57: | if c == 57: | Use == for comparison. | Python |
<div><p>output</div></p> | <div><p>output</p></div> | Nest properly. | HTML |
let result: i32 = "test"; | let result: &str = "test"; | Type mismatch. | Rust |
arr[10] | if (arr.indices.contains(10)) arr[10] | Check index. | Kotlin |
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 |
def render
puts 'info'
end | def render
puts 'info'
end | Correct. | Ruby |
let a: Int = 'info' | let a: String = 'info' | Fix type. | Swift |
SELECT * FROM items WHRE email=27; | SELECT * FROM items WHERE email=27; | Fix WHERE. | SQL |
if ($y = 15) | if ($y == 15) | Use ==. | Perl |
var x int = 'world' | var x string = 'world' | Type mismatch. | Go |
bar == '8' | bar === 8 | Use strict equality. | JavaScript |
#content {{ color: blue; }} | #content {{ color: blue; }} | Correct. | CSS |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
if x > 16
puts 'output' | if x > 16
puts 'output'
end | Add 'end'. | Ruby |
int[] data = new int[69];
data[69] = 5; | int[] data = new int[69];
if (69 < data.length) data[69] = 5; | Check bounds. | Java |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
def process():
print('data') | def process():
print('data') | Indent function body. | Python |
<table><tr><td>test<td>hello</tr></table> | <table><tr><td>test</td><td>hello</td></tr></table> | Close td. | HTML |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(3); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(3, () => console.log('listening')); | Add callback. | Node.js |
function handle() {{
return
{{key:'test'}}
}} | function handle() {{
return {{key:'test'}};
}} | Return object on same line. | JavaScript |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
Write-Host 'hello' | Write-Host 'hello' | Correct. | PowerShell |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
data[11] | if (length(data) >= 11) data[11] | Check length. | R |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
if bar = 72 | if bar == 72 | Use ==. | MATLAB |
<center>info</center> | <div style='text-align:center;'>info</div> | Use CSS. | HTML |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.