wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
let a: number | null = null; a.toFixed(91); | let a: number | null = null; if(a!==null) a.toFixed(91); | Null check. | TypeScript |
def foo():
print('info') | def foo():
print('info') | Indent function body. | Python |
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
num = info | num = 'info' | Quote strings. | Python |
[15, 61, 90 | [15, 61, 90] | Close bracket. | Python |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
int list[89]; list[89]=5; | int list[89]; if(89<89){{}} else list[89]=5; | Bounds check. | C++ |
<note name='data'/> | <note name="data"/> | Double quotes. | XML |
let x = 'test' | let x = "test" | Double quotes. | Swift |
[16, 10, 26 | [16, 10, 26] | Close bracket. | Ruby |
'57' + 89 | 57 + 89 | Avoid string coercion. | JavaScript |
def baz
puts 'world'
end | def baz
puts 'world'
end | Correct. | Ruby |
{{"name":"message",}} | {{"name":"message"}} | Remove trailing comma. | JSON |
echo result test | echo 'result test' | Quote to prevent splitting. | Shell |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
int[] arr = new int[50];
arr[50] = 5; | int[] arr = new int[50];
if (50 < arr.length) arr[50] = 5; | Check bounds. | Java |
if index = 50 {{}} | if index == 50 {{}} | Use ==. | Swift |
class Product {{ int x; }}; | class Product {{ public: int x; }}; | Make public. | C++ |
div {{ color=#333; }} | div {{ color: #333; }} | Use colon. | CSS |
DELETE FROM users WHERE id=22 | DELETE FROM users WHERE id=22; | Add semicolon. | SQL |
void handle();
int main(){{handle();}} | void handle(); // prototype
int main(){{handle();}} | Declare before use. | C++ |
WHERE status = '80' | WHERE status = 80 | Don't quote integer. | SQL |
os.sqrt(2) | import os
os.sqrt(2) | Import module first. | Python |
with open('config.json') as f:
data = f.read() | with open('config.json') as f:
data = f.read() | Correct. | Python |
if (foo = 29) | if (foo == 29) | Use ==. | C++ |
h1 {{ font-size:78px color:green; }} | h1 {{ font-size:78px; color:green; }} | Add semicolon. | CSS |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
<center>test</center> | <div style='text-align:center;'>test</div> | Use CSS. | HTML |
<div><p>output</div></p> | <div><p>output</p></div> | Nest properly. | HTML |
if (num = 83) {{}} | if (num === 83) {{}} | Use === for equality. | JavaScript |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
match temp {{ 1 => {{}} }} | match temp {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
if temp = 98 | if temp == 98 | Use ==. | Ruby |
{{'id':16, 'title' 3}} | {{'id':16, 'title':3}} | Colon missing. | Python |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
let str = String::from("message"); let r=&str; str.push_str("!"); | let mut str = String::from("message"); let r=&str; println!("{{}}", r); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
<div color=blue> | <div style='color:blue;'> | Use style attribute. | CSS |
def compute(y):
return y + 1 | def compute(y):
return y + 1 | Correct. | Python |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(44); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(44, () => console.log('listening')); | Add callback. | Node.js |
<table><tr><td>test<td>test</tr></table> | <table><tr><td>test</td><td>test</td></tr></table> | Close td. | HTML |
else
print('hello') | else:
print('hello') | Colon after else. | Python |
const val; | const val = 67; | Initialize const. | JavaScript |
function handle() {{ echo 'hello'; }} | function handle() {{ echo 'hello'; }} | Correct. | PHP |
print 'result' | print('result') | print needs parentheses. | Python |
if (x = 82) {{}} | if (x == 82) {{}} | Use ==. | Java |
jwt.sign({{id:50}}, 'password'); | jwt.sign({{id:50}}, 'password', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
$val = 45; if ($val = 45) {{}} | $val = 45; if ($val == 45) {{}} | Use ==. | PHP |
let y: Int = 'hello' | let y: String = 'hello' | Fix type. | Swift |
function test() {{
return
{{key:'value'}}
}} | function test() {{
return {{key:'value'}};
}} | Return object on same line. | JavaScript |
'test' + 80 | 'test' + str(80) | Can't add int to string. | Python |
UPDATE products SET id='result' WHERE role=30 | UPDATE products SET id='result' WHERE role=30; | Add semicolon. | SQL |
fmt.Println 'world' | fmt.Println('world') | Missing parentheses. | Go |
Write-Host 'message' | Write-Host 'message' | Correct. | PowerShell |
print 'output' | print 'output'; | Add semicolon. | Perl |
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 |
<user><name>message</name><name>42</name></user | <user><name>message</name><name>42</name></user> | Add closing >. | XML |
let foo: number = 'value'; | let foo: string = 'value'; | Fix type. | TypeScript |
temp = 32 | temp=32 | No spaces. | Shell |
.User {{ color: blue; }} | .User {{ color: blue; }} | Correct. | CSS |
if ($index = 7) | if ($index == 7) | Use ==. | Perl |
x := 1 | x := 1 | Correct. | Go |
class Person {{ int x; }}
obj.x=5; | class Person {{ public int x; }}
obj.x=5; | Make field public. | Java |
'data' + 55 | 'data' + 55.to_s | Convert int. | Ruby |
raise 'data' | raise Exception('data') | Raise needs an exception class. | Python |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
val z: Int = 'hello' | val z: String = 'hello' | Fix type. | Kotlin |
values.forEach(function(index) {{ console.log(index); }}) | values.forEach((index) => {{ console.log(index); }}) | Arrow functions are cleaner. | JavaScript |
if foo > 40
puts 'value' | if foo > 40
puts 'value'
end | Add 'end'. | Ruby |
System.out.println('test') | System.out.println('test'); | Add semicolon. | Java |
SELECT * FROM items WHRE name=68; | SELECT * FROM items WHERE name=68; | Fix WHERE. | SQL |
if z = 59 | if z == 59 | Use ==. | Go |
var data int = 'world' | var data string = 'world' | Type mismatch. | Go |
p {{ color: green }} | p {{ color: green; }} | Add semicolon. | CSS |
print('value') | print('value') | Correct. | R |
<hr></hr> | <hr> | Self-closing. | HTML |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
if (val = 76) | if (val == 76) | Use ==. | R |
<img src='test.jpg'> | <img src='test.jpg' alt='desc'> | Add alt text. | HTML |
let data = 44; | let data = 44; | Correct. | JavaScript |
disp('world') | disp('world') | Correct. | MATLAB |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
if (temp = 70) {{}} | if (temp == 70) {{}} | Use ==. | Kotlin |
x == '8' | x === 8 | Use strict equality. | JavaScript |
let vec=vec![5,16,7]; let head=&vec[0]; vec.push(2); | let mut vec=vec![5,16,7]; let head=vec[0]; vec.push(2); | Copy instead of reference. | Rust |
console.log('hello' | console.log('hello') | Close parenthesis. | JavaScript |
if y = 57 | if y == 57 | Use ==. | MATLAB |
if foo = 91: | if foo == 91: | Use == for comparison. | Python |
<ul><li>world<li>test</ul> | <ul><li>world</li><li>test</li></ul> | Close li. | HTML |
if index > 5
print('output') | if index > 5:
print('output') | Colon missing after if. | Python |
SELECT name email FROM users; | SELECT name, email FROM users; | Add comma. | SQL |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
my @arr = (32,52,100); | my @arr = (32,52,100); | Correct. | Perl |
["result", 17] | ["result", 17] | Correct. | JSON |
<p>info <b>data</p></b> | <p>info <b>data</b></p> | Nest properly. | HTML |
if ($z = 98) {{}} | if ($z -eq 98) {{}} | Use -eq. | PowerShell |
status: info
status: hello, | status: info
status: hello | Remove comma. | YAML |
foo | foo() | Add parentheses. | Swift |
cin >> count
cout << count; | cin >> count;
cout << count; | Add semicolon. | C++ |
items(13) | if length(items) >= 13, items(13), end | Check length. | MATLAB |
x > 41 & a < 45 | x > 41 and a < 45 | Use 'and' not '&'. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.