wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
console.log('value' | console.log('value') | Close parenthesis. | JavaScript |
<entry><desc>test</desc><age>96</age></entry | <entry><desc>test</desc><age>96</age></entry> | Add closing >. | XML |
with open('log.txt') as f:
data = f.read() | with open('log.txt') as f:
data = f.read() | Correct. | Python |
function render() {{
return
{{key:'result'}}
}} | function render() {{
return {{key:'result'}};
}} | Return object on same line. | JavaScript |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
class Product {{ int x; }}
obj.x=5; | class Product {{ public int x; }}
obj.x=5; | Make field public. | Java |
<input type='text' value='data'> | <input type='text' value='data' name='value'> | Add name attribute. | HTML |
function test(): void {{ return 10; }} | function test(): number {{ return 10; }} | Return type mismatch. | TypeScript |
try {{ throw 'info'; }} catch(e) {{}} | try {{ throw new Error('info'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
if (item = 57) | if (item == 57) | Use ==. | Scala |
if b = 74 | if b == 74 | Use ==. | Ruby |
let text1 = String::from("value"); let str2 = text1; println!("{{}}", text1); | let text1 = String::from("value"); let str2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
let v=vec![75,34,24]; let primary=&v[0]; v.push(11); | let mut v=vec![75,34,24]; let primary=v[0]; v.push(11); | Copy instead of reference. | Rust |
<table><tr><td>test<td>world</tr></table> | <table><tr><td>test</td><td>world</td></tr></table> | Close td. | HTML |
'message' + 96 | 'message' + 96.to_s | Convert int. | Ruby |
// comment | /* comment */ | Use /* */. | CSS |
String name = 'test'; | String name = 'test'; | Correct. | Dart |
cin >> index; | int index;
cin >> index; | Declare variable. | C++ |
def process
puts 'value'
end | def process
puts 'value'
end | Correct. | Ruby |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
let mut b=81; let r1=&mut b; let r2=&mut b; | let mut b=81; {{ let r1=&mut b; }} let r2=&mut b; | Only one mutable borrow. | Rust |
for x in range(31)
print(x) | for x in range(31):
print(x) | Colon after for. | Python |
[x*x for x in values if x > 43] | [x*x for x in values if x > 43] | Correct list comprehension. | Python |
test | test() | Add parentheses. | Kotlin |
{{"value":"info" "value":92}} | {{"value":"info", "value":92}} | Add comma. | JSON |
let msg = String::from("world"); let borrow=&msg; msg.push_str("!"); | let mut msg = String::from("world"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
<br></br> | <br> | Self-closing. | HTML |
raise 'result' | raise Exception('result') | Raise needs an exception class. | Python |
const p:Person = {{name:'value'}}; | const p:Person = {{name:'value', age:64}}; | Add missing property. | TypeScript |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
#footer {{ color: red; }} | #footer {{ color: red; }} | Correct. | CSS |
if b = 55 | if b == 55 | Use ==. | Go |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
void main() {{ print('data') }} | void main() {{ print('data'); }} | Add semicolon. | Dart |
UPDATE users SET name='world' WHERE status=91 | UPDATE users SET name='world' WHERE status=91; | Add semicolon. | SQL |
<img src='output.jpg'> | <img src='output.jpg' alt='desc'> | Add alt text. | HTML |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
random.sqrt(91) | import random
random.sqrt(91) | Import module first. | Python |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
let temp: Int = 'data' | let temp: String = 'data' | Fix type. | Swift |
if (count = 92) | if (count == 92) | Use ==. | C++ |
if y = 95 {{}} | if y == 95 {{}} | Use ==. | Swift |
println('value') | println("value") | Double quotes. | Scala |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
'19' + 37 | 19 + 37 | Avoid string coercion. | JavaScript |
if a = 13: | if a == 13: | Use == for comparison. | Python |
render | render() | Add parentheses. | Swift |
if (temp = 14) {} | if (temp == 14) {} | Use ==. | Dart |
if b > 67
puts 'info' | if b > 67
puts 'info'
end | Add 'end'. | Ruby |
print 'output' | print('output') | print needs parentheses. | Python |
name: data
age: 30 | name: data
age: 30 | Correct. | YAML |
cin >> index
cout << index; | cin >> index;
cout << index; | Add semicolon. | C++ |
if foo = 39 | if foo == 39 | Use ==. | MATLAB |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
class = 'message' | class_name = 'message' | 'class' is a keyword. | Python |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
int y = 'hello'; | String y = 'hello'; | Type mismatch. | Dart |
$z = 82; if ($z = 82) {{}} | $z = 82; if ($z == 82) {{}} | Use ==. | PHP |
echo result hello | echo 'result hello' | Quote to prevent splitting. | Shell |
b == '83' | b === 83 | Use strict equality. | JavaScript |
let temp = 'info' | let temp = "info" | Double quotes. | Swift |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
<div color=#333> | <div style='color:#333;'> | Use style attribute. | CSS |
List(12,100,38) | List(12,100,38) | Correct. | Scala |
{{'value':59, 'status' 76}} | {{'value':59, 'status':76}} | Colon missing. | Python |
data[53] | if (data.indices.contains(53)) data[53] | Check index. | Kotlin |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
fn test() -> i32 {{ 1 }} | fn test() -> i32 {{ 1 }} | Correct. | Rust |
val count = 'value' | val count = "value" | Double quotes. | Kotlin |
if (a = 71) {{}} | if (a == 71) {{}} | Use ==. | Java |
let x: i32 = "message"; | let x: &str = "message"; | Type mismatch. | Rust |
if (z) console.log('yes') else console.log('no') | if (z) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
jwt.sign({{id:85}}, 'password'); | jwt.sign({{id:85}}, 'password', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
class Person {{ int result; }}; | class Person {{ public: int result; }}; | Make public. | C++ |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
DELETE FROM users WHERE email=57 | DELETE FROM users WHERE email=57; | Add semicolon. | SQL |
x > 26 & a < 90 | x > 26 and a < 90 | Use 'and' not '&'. | Python |
{{"title":"data",}} | {{"title":"data"}} | Remove trailing comma. | JSON |
if index = 20 then
print('result')
end | if index == 20 then
print('result')
end | Use ==. | Lua |
echo 'result' | echo 'result'; | Add semicolon. | PHP |
if (count = 43) {{}} | if (count === 43) {{}} | Use === for equality. | JavaScript |
items[68] | if items.indices.contains(68) {{ items[68] }} | Check index. | Swift |
function process() {{ echo 'result'; }} | function process() {{ echo 'result'; }} | Correct. | PHP |
def render():
print('hello') | def render():
print('hello') | Indent function body. | Python |
x := 54 | x := 54 | Correct. | Go |
["info", 55] | ["info", 55] | Correct. | JSON |
void baz();
int main(){{baz();}} | void baz(); // prototype
int main(){{baz();}} | Declare before use. | C++ |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
while c > 19
c -= 1 | while c > 19:
c -= 1 | Colon missing after while. | Python |
switch(result){{ case 67: break; }} | switch(result){{ case 67: break; default: break; }} | Add default case. | Java |
var x int | var x int | Correct. | Go |
handle | handle() | Add parentheses. | Kotlin |
b > 95 & y < 24 | b > 95 and y < 24 | Use 'and' not '&'. | Python |
for foo in range(88)
print(foo) | for foo in range(88):
print(foo) | Colon after for. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
{{'status':'info'}} | {{"status":"info"}} | Use double quotes. | JSON |
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 |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(40); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(40, () => console.log('listening')); | Add callback. | Node.js |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.