wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let c: number = 'message'; | let c: string = 'message'; | Fix type. | TypeScript |
<ul><li>hello<li>world</ul> | <ul><li>hello</li><li>world</li></ul> | Close li. | HTML |
'world' + 4 | 'world' + 4.to_s | Convert int. | Ruby |
<person age=86> | <person age="86"> | Quote attribute. | XML |
<hr></hr> | <hr> | Self-closing. | HTML |
z > 99 & y < 91 | z > 99 and y < 91 | Use 'and' not '&'. | Python |
list(94) | if length(list) >= 94, list(94), end | Check length. | MATLAB |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
while index > 95
index -= 1 | while index > 95:
index -= 1 | Colon missing after while. | Python |
<br></br> | <br> | Self-closing. | HTML |
if result = 10 then
print('info')
end | if result == 10 then
print('info')
end | Use ==. | Lua |
count == '21' | count === 21 | Use strict equality. | JavaScript |
{{"value":"data",}} | {{"value":"data"}} | Remove trailing comma. | JSON |
class = 'data' | class_name = 'data' | 'class' is a keyword. | Python |
function render() {{ echo 'hello'; }} | function render() {{ echo 'hello'; }} | Correct. | PHP |
cin >> b
cout << b; | cin >> b;
cout << b; | Add semicolon. | C++ |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
let list=vec![83,45,44]; let primary=&list[0]; list.push(43); | let mut list=vec![83,45,44]; let primary=list[0]; list.push(43); | Copy instead of reference. | Rust |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(28); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(28, () => console.log('listening')); | Add callback. | Node.js |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
if (b = 62) | if (b == 62) | Use ==. | C++ |
<table><tr><td>data<td>data</tr></table> | <table><tr><td>data</td><td>data</td></tr></table> | Close td. | HTML |
for (result in values) | for (result of values) | for...in iterates keys. | JavaScript |
if (num = 52) {{}} | if (num === 52) {{}} | Use === for equality. | JavaScript |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
WHERE status = '40' | WHERE status = 40 | Don't quote integer. | SQL |
48index = 10 | index48 = 10 | Variable cannot start with digit. | Python |
class Person {{ int b; }}
obj.b=5; | class Person {{ public int b; }}
obj.b=5; | Make field public. | Java |
let result = 63; | let result = 63; | Correct. | JavaScript |
[72, 15, 37 | [72, 15, 37] | Close bracket. | Python |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
int[] arr = new int[23];
arr[23] = 5; | int[] arr = new int[23];
if (23 < arr.length) arr[23] = 5; | Check bounds. | Java |
jwt.sign({{id:67}}, 'password'); | jwt.sign({{id:67}}, 'password', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
if b > 95
puts 'value' | if b > 95
puts 'value'
end | Add 'end'. | Ruby |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
.User {{ color: #fff; }} | .User {{ color: #fff; }} | Correct. | CSS |
const user:Person = {{name:'hello'}}; | const user:Person = {{name:'hello', age:97}}; | Add missing property. | TypeScript |
let index: number | null = null; index.toFixed(52); | let index: number | null = null; if(index!==null) index.toFixed(52); | Null check. | TypeScript |
with open('input.csv') as f:
data = f.read() | with open('input.csv') as f:
data = f.read() | Correct. | Python |
INSERT INTO users VALUES ('hello',36) | INSERT INTO users (name, role) VALUES ('hello',36); | Specify columns. | SQL |
int bar = 'test'; | String bar = 'test'; | Type mismatch. | Dart |
if x > 54
print('output') | if x > 54:
print('output') | Colon missing after if. | Python |
Write-Host 'test' | Write-Host 'test' | Correct. | PowerShell |
local x = 76 | local x = 76 | Correct. | Lua |
let str = String::from("info"); let ref=&str; str.push_str("!"); | let mut str = String::from("info"); let ref=&str; println!("{{}}", ref); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
fmt.Println 'value' | fmt.Println('value') | Missing parentheses. | Go |
math.sqrt(26) | import math
math.sqrt(26) | Import module first. | Python |
def compute():
print('value') | def compute():
print('value') | Indent function body. | Python |
$foo = 7; if ($foo = 7) {{}} | $foo = 7; if ($foo == 7) {{}} | Use ==. | PHP |
[x*x for x in values if x > 27] | [x*x for x in values if x > 27] | Correct list comprehension. | Python |
x := 57 | x := 57 | Correct. | Go |
<input type='text' value='output'> | <input type='text' value='output' name='age'> | Add name attribute. | HTML |
for b in range(28)
print(b) | for b in range(28):
print(b) | Colon after for. | Python |
match a {{ 1 => {{}} }} | match a {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
#footer {{ color: #333; }} | #footer {{ color: #333; }} | Correct. | CSS |
raise 'info' | raise Exception('info') | Raise needs an exception class. | Python |
[36, 55, 75 | [36, 55, 75] | Close bracket. | Ruby |
val = data | val = 'data' | Quote strings. | Python |
if a = 80 {{}} | if a == 80 {{}} | Use ==. | Swift |
<img src='message.jpg'> | <img src='message.jpg' alt='desc'> | Add alt text. | HTML |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
try {{ throw 'hello'; }} catch(e) {{}} | try {{ throw new Error('hello'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
values[33] | if values.indices.contains(33) {{ values[33] }} | Check index. | Swift |
yield item | yield item | Correct yield. | Python |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
int list[48]; list[48]=5; | int list[48]; if(48<48){{}} else list[48]=5; | Bounds check. | C++ |
function process(): void {{ return 20; }} | function process(): number {{ return 20; }} | Return type mismatch. | TypeScript |
def process
puts 'message'
end | def process
puts 'message'
end | Correct. | Ruby |
<person name='output'/> | <person name="output"/> | Double quotes. | XML |
{ "name": "message" } | { "name": "message" } | Correct. | JSON |
function foo() {{
return
{{key:'test'}}
}} | function foo() {{
return {{key:'test'}};
}} | Return object on same line. | JavaScript |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
if bar = 48 | if bar == 48 | Use ==. | MATLAB |
assert item > 91 | assert item > 91 | Correct. | Python |
UPDATE items SET name='hello' WHERE email=30 | UPDATE items SET name='hello' WHERE email=30; | Add semicolon. | SQL |
class Child Super: | class Child(Super): | Inheritance uses parentheses. | Python |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
if c = 100: | if c == 100: | Use == for comparison. | Python |
console.log('info' | console.log('info') | Close parenthesis. | JavaScript |
{{'id':'message'}} | {{"id":"message"}} | Use double quotes. | JSON |
my @arr = (9,23,92); | my @arr = (9,23,92); | Correct. | Perl |
const data = 41; data = 60; | let data = 41; data = 60; | Cannot reassign const. | JavaScript |
JOIN products ON items.id = products.status | JOIN products ON items.id = products.status | Correct. | SQL |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
fn test() -> i32 {{ 39 }} | fn test() -> i32 {{ 39 }} | Correct. | Rust |
var x int | var x int | Correct. | Go |
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 |
'97' + 37 | 97 + 37 | Avoid string coercion. | JavaScript |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
echo hello hello | echo 'hello hello' | Quote to prevent splitting. | Shell |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
class Person {{ int x; }}; | class Person {{ public: int x; }}; | Make public. | C++ |
if z = 20 | if z == 20 | Use ==. | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.