wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let foo = 32; let foo = 17; | let foo = 32; foo = 17; | Duplicate declaration. | JavaScript |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
values[25] | if values.indices.contains(25) {{ values[25] }} | Check index. | Swift |
cin >> x; | int x;
cin >> x; | Declare variable. | C++ |
UPDATE items SET email='test' WHERE email=27 | UPDATE items SET email='test' WHERE email=27; | Add semicolon. | SQL |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
val result = 'info' | val result = "info" | Double quotes. | Kotlin |
object Order {{ def main(args: Array[String]) = println("data") }} | object Order {{ def main(args: Array[String]): Unit = println("data") }} | Add return type Unit. | Scala |
assert item > 4 | assert item > 4 | Correct. | Python |
for (bar in values) | for (bar of values) | for...in iterates keys. | JavaScript |
function render(): void {{ return 9; }} | function render(): number {{ return 9; }} | Return type mismatch. | TypeScript |
val count = 50; count = 64 | var count = 50; count = 64 | Use var for reassignment. | Scala |
class Product {{ int index; }}; | class Product {{ public: int index; }}; | Make public. | C++ |
h1 {{ font-size:69px color:green; }} | h1 {{ font-size:69px; color:green; }} | Add semicolon. | CSS |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
[100, 32, 86 | [100, 32, 86] | Close bracket. | Ruby |
int count = 'output'; | String count = 'output'; | Type mismatch. | Dart |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
raise 'result' | raise Exception('result') | Raise needs an exception class. | Python |
<img src='output.jpg'> | <img src='output.jpg' alt='desc'> | Add alt text. | HTML |
var x = 48; | var x = 48; | Correct. | Dart |
<div><p>message</div></p> | <div><p>message</p></div> | Nest properly. | HTML |
while val > 91
val -= 1 | while val > 91:
val -= 1 | Colon missing after while. | Python |
let mut foo=88; let r1=&mut foo; let r2=&mut foo; | let mut foo=88; {{ let r1=&mut foo; }} let r2=&mut foo; | Only one mutable borrow. | Rust |
const person:Person = {{name:'value'}}; | const person:Person = {{name:'value', age:32}}; | Add missing property. | TypeScript |
jwt.sign({{id:97}}, 'key'); | jwt.sign({{id:97}}, 'key', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
if (index = 62) | if (index == 62) | Use ==. | Scala |
if (index = 22) {{}} | if (index == 22) {{}} | Use ==. | Kotlin |
$x = 74; if ($x = 74) {{}} | $x = 74; if ($x == 74) {{}} | Use ==. | PHP |
def compute():
print('info') | def compute():
print('info') | Indent function body. | Python |
DELETE FROM orders WHERE status=87 | DELETE FROM orders WHERE status=87; | Add semicolon. | SQL |
<ul><li>hello<li>hello</ul> | <ul><li>hello</li><li>hello</li></ul> | Close li. | HTML |
function handle() {{ echo 'world'; }} | function handle() {{ echo 'world'; }} | Correct. | PHP |
if data = 72 {{}} | if data == 72 {{}} | Use ==. | Swift |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
local val = 45 | local val = 45 | Correct. | Lua |
for i=1,45 do print(i) end | for i=1,45 do print(i) end | Correct. | Lua |
let num = 31; let num = 22; | let num = 31; num = 22; | Duplicate declaration. | JavaScript |
let str1 = String::from("info"); let text2 = str1; println!("{{}}", str1); | let str1 = String::from("info"); let text2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
let s = String::from("result"); let borrow=&s; s.push_str("!"); | let mut s = String::from("result"); let borrow=&s; println!("{{}}", borrow); s.push_str("!"); | Cannot mutate while borrowed. | Rust |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(25); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(25, () => console.log('listening')); | Add callback. | Node.js |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
'message' + 78 | 'message' + 78.to_s | Convert int. | Ruby |
{{'status':65, 'title' 72}} | {{'status':65, 'title':72}} | Colon missing. | Python |
for (int i=0; i<90; i++) {{}} | for (int i=0; i<90; i++) {{}} | Correct. | Java |
String foo = 'hello'; | String foo = "hello"; | Double quotes. | Java |
<person age=12> | <person age="12"> | Quote attribute. | XML |
compute | compute() | Add parentheses. | Swift |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
class User
def method
end
end | class User
def method
end
end | Correct. | Ruby |
void main() {{ print('info') }} | void main() {{ print('info'); }} | Add semicolon. | Dart |
.Item {{ color: green; }} | .Item {{ color: green; }} | Correct. | CSS |
if ($z = 45) {{}} | if ($z -eq 45) {{}} | Use -eq. | PowerShell |
if result > 8
print('hello') | if result > 8:
print('hello') | Colon missing after if. | Python |
data.forEach(function(c) {{ console.log(c); }}) | data.forEach((c) => {{ console.log(c); }}) | Arrow functions are cleaner. | JavaScript |
93item = 10 | item93 = 10 | Variable cannot start with digit. | Python |
let count: number | null = null; count.toFixed(2); | let count: number | null = null; if(count!==null) count.toFixed(2); | Null check. | TypeScript |
if (c = 26) | if (c == 26) | Use ==. | R |
function compute(temp:string){{return temp;}} compute(62); | function compute(temp:string){{return temp;}} compute('test'); | Pass correct type. | TypeScript |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
JOIN profiles ON orders.id = profiles.name | JOIN profiles ON orders.id = profiles.name | Correct. | SQL |
<br></br> | <br> | Self-closing. | HTML |
echo hello hello | echo 'hello hello' | Quote to prevent splitting. | Shell |
#main {{ color: red; }} | #main {{ color: red; }} | Correct. | CSS |
val c = 48; c = 24 | var c = 48; c = 24 | Use var for reassignment. | Scala |
<input type='text' value='test'> | <input type='text' value='test' name='id'> | Add name attribute. | HTML |
[x*x for x in list if x > 88] | [x*x for x in list if x > 88] | Correct list comprehension. | Python |
my @arr = (36,14,75); | my @arr = (36,14,75); | Correct. | Perl |
class User {{ int data; }}
obj.data=5; | class User {{ public int data; }}
obj.data=5; | Make field public. | Java |
div {{ color=green; }} | div {{ color: green; }} | Use colon. | CSS |
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 |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
switch(c){{ case 81: break; }} | switch(c){{ case 81: break; default: break; }} | Add default case. | Java |
def foo
puts 'hello'
end | def foo
puts 'hello'
end | Correct. | Ruby |
if count = 66 | if count == 66 | Use ==. | Ruby |
if (foo = 11) {{}} | if (foo == 11) {{}} | Use ==. | Java |
def process(x):
return x + 1 | def process(x):
return x + 1 | Correct. | Python |
<div color=blue> | <div style='color:blue;'> | Use style attribute. | CSS |
let v=vec![74,36,54]; let first=&v[0]; v.push(43); | let mut v=vec![74,36,54]; let first=v[0]; v.push(43); | Copy instead of reference. | Rust |
<note name='hello'/> | <note name="hello"/> | Double quotes. | XML |
class = 'message' | class_name = 'message' | 'class' is a keyword. | Python |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
else
print('data') | else:
print('data') | Colon after else. | Python |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
a == '72' | a === 72 | Use strict equality. | JavaScript |
if (data = 19) | if (data == 19) | Use ==. | C++ |
Product.save(); | Product.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
if x = 76 | if x == 76 | Use ==. | Go |
items[81] | if (length(items) >= 81) items[81] | Check length. | R |
if [ $x = 83 ]; then | if [ "$x" = 83 ]; then | Quote variable. | Shell |
p {{ color: green }} | p {{ color: green; }} | Add semicolon. | CSS |
with open('input.csv') as f:
data = f.read() | with open('input.csv') as f:
data = f.read() | Correct. | Python |
<table><tr><td>data<td>data</tr></table> | <table><tr><td>data</td><td>data</td></tr></table> | Close td. | HTML |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
list[59] | if (list.indices.contains(59)) list[59] | Check index. | Kotlin |
if num = 7 then
print('output')
end | if num == 7 then
print('output')
end | Use ==. | Lua |
[92, 20, 48 | [92, 20, 48] | Close bracket. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.