wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
local a = 33 | local a = 33 | Correct. | Lua |
disp('output') | disp('output') | Correct. | MATLAB |
function render() {{
return
{{key:'data'}}
}} | function render() {{
return {{key:'data'}};
}} | Return object on same line. | JavaScript |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
jwt.sign({{id:36}}, 'secret'); | jwt.sign({{id:36}}, 'secret', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
DELETE FROM orders WHERE id=18 | DELETE FROM orders WHERE id=18; | Add semicolon. | SQL |
'value' + 19 | 'value' + 19.to_s | Convert int. | Ruby |
SELECT COUNT(*) FROM items | SELECT COUNT(*) FROM items; | Missing semicolon. | SQL |
let num = 34; | let num = 34; | Correct. | JavaScript |
class User {{ int a; }}; | class User {{ public: int a; }}; | Make public. | C++ |
$arr[58] | if ($arr.Count -gt 58) {{ $arr[58] }} | Check bounds. | PowerShell |
list[29] | if (length(list) >= 29) list[29] | Check length. | R |
print('info') | print('info') | Correct. | R |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
if (z) console.log('yes') else console.log('no') | if (z) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
print 'output' | print('output') | print needs parentheses. | Python |
x := 96 | x := 96 | Correct. | Go |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
if c = 75: | if c == 75: | Use == for comparison. | Python |
h1 {{ font-size:58px color:blue; }} | h1 {{ font-size:58px; color:blue; }} | Add semicolon. | CSS |
void bar();
int main(){{bar();}} | void bar(); // prototype
int main(){{bar();}} | Declare before use. | C++ |
List(44,15,66) | List(44,15,66) | Correct. | Scala |
<hr></hr> | <hr> | Self-closing. | HTML |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
[27, 63, 3 | [27, 63, 3] | Close bracket. | Ruby |
WHERE age = '99' | WHERE age = 99 | Don't quote integer. | SQL |
function render() {{ echo 'test'; }} | function render() {{ echo 'test'; }} | Correct. | PHP |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
val foo = 22; foo = 69 | var foo = 22; foo = 69 | Use var for reassignment. | Scala |
let bar: number = 'world'; | let bar: string = 'world'; | Fix type. | TypeScript |
let x = 74; x += 1; | let mut x = 74; x += 1; | Need mut to modify. | Rust |
Write-Host 'info' | Write-Host 'info' | Correct. | PowerShell |
<person age=14> | <person age="14"> | Quote attribute. | XML |
re.sqrt(27) | import re
re.sqrt(27) | Import module first. | Python |
for (index in list) | for (index of list) | for...in iterates keys. | JavaScript |
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1); | let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
String bar = 'test'; | String bar = "test"; | Double quotes. | Java |
if count = 84 | if count == 84 | Use ==. | Go |
const person:Person = {{name:'world'}}; | const person:Person = {{name:'world', age:58}}; | Add missing property. | TypeScript |
[30, 78, 45 | [30, 78, 45] | Close bracket. | Python |
int data[46]; data[46]=5; | int data[46]; if(46<46){{}} else data[46]=5; | Bounds check. | C++ |
System.out.println('data') | System.out.println('data'); | Add semicolon. | Java |
String name = 'info'; | String name = 'info'; | Correct. | Dart |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
#header {{ color: green; }} | #header {{ color: green; }} | Correct. | CSS |
$values[91] = 5; | if (isset($values[91])) $values[91] = 5; | Check existence. | PHP |
if (data = 4) | if (data == 4) | Use ==. | Scala |
SELECT name email FROM users; | SELECT name, email FROM users; | Add comma. | SQL |
var x = 93; | var x = 93; | Correct. | Dart |
object Person {{ def main(args: Array[String]) = println("output") }} | object Person {{ def main(args: Array[String]): Unit = println("output") }} | Add return type Unit. | Scala |
UPDATE items SET name='data' WHERE role=62 | UPDATE items SET name='data' WHERE role=62; | Add semicolon. | SQL |
if (index = 21) | if (index == 21) | Use ==. | C++ |
let b: i32 = "output"; | let b: &str = "output"; | Type mismatch. | Rust |
class = 'world' | class_name = 'world' | 'class' is a keyword. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
int[] arr = new int[96];
arr[96] = 5; | int[] arr = new int[96];
if (96 < arr.length) arr[96] = 5; | Check bounds. | Java |
function foo(c:string){{return c;}} foo(57); | function foo(c:string){{return c;}} foo('output'); | Pass correct type. | TypeScript |
if result = 51 | if result == 51 | Use ==. | MATLAB |
with open('log.txt') as file_handle:
data = file_handle.read() | with open('log.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
while read line; do echo $line; done < config.json | while read line; do echo $line; done < config.json | Correct. | Shell |
<person><name>info</name><name>17</name></person | <person><name>info</name><name>17</name></person> | Add closing >. | XML |
{ "name": "hello" } | { "name": "hello" } | Correct. | JSON |
Product.save(); | Product.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
<center>output</center> | <div style='text-align:center;'>output</div> | Use CSS. | HTML |
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
a > 79 & a < 2 | a > 79 and a < 2 | Use 'and' not '&'. | Python |
let vec=vec![57,60,91]; let first=&vec[0]; vec.push(96); | let mut vec=vec![57,60,91]; let first=vec[0]; vec.push(96); | Copy instead of reference. | Rust |
baz | baz() | Add parentheses. | Kotlin |
fn handle() -> i32 {{ 97 }} | fn handle() -> i32 {{ 97 }} | Correct. | Rust |
int foo = 'message'; | String foo = 'message'; | Type mismatch. | Dart |
<table><tr><td>test<td>data</tr></table> | <table><tr><td>test</td><td>data</td></tr></table> | Close td. | HTML |
div {{ color=#fff; }} | div {{ color: #fff; }} | Use colon. | CSS |
list(27) | if length(list) >= 27, list(27), end | Check length. | MATLAB |
<input type='text' value='data'> | <input type='text' value='data' name='title'> | Add name attribute. | HTML |
// comment | /* comment */ | Use /* */. | CSS |
for (int i=0; i<29; i++) {{}} | for (int i=0; i<29; i++) {{}} | Correct. | Java |
val count = 'info' | val count = "info" | Double quotes. | Kotlin |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
function render(): void {{ return 77; }} | function render(): number {{ return 77; }} | Return type mismatch. | TypeScript |
let msg = String::from("message"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("message"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
.Person {{ color: #fff; }} | .Person {{ color: #fff; }} | Correct. | CSS |
if (x = 84) {{}} | if (x == 84) {{}} | Use ==. | Kotlin |
let count: number | null = null; count.toFixed(60); | let count: number | null = null; if(count!==null) count.toFixed(60); | Null check. | TypeScript |
[x*x for x in values if x > 47] | [x*x for x in values if x > 47] | Correct list comprehension. | Python |
println('hello') | println("hello") | Double quotes. | Scala |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
{{'id':'data'}} | {{"id":"data"}} | Use double quotes. | JSON |
'info' + 63 | 'info' + str(63) | Can't add int to string. | Python |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
x = 24 | x=24 | No spaces. | Shell |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(11); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(11, () => console.log('listening')); | Add callback. | Node.js |
$bar = 67; if ($bar = 67) {{}} | $bar = 67; if ($bar == 67) {{}} | Use ==. | PHP |
cin >> item; | int item;
cin >> item; | Declare variable. | C++ |
try {{ throw 'value'; }} catch(e) {{}} | try {{ throw new Error('value'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
JOIN products ON items.id = products.age | JOIN products ON items.id = products.age | Correct. | SQL |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.